1. 程式人生 > >Android開啟QQ臨時會話以及一鍵加群的兩種方法

Android開啟QQ臨時會話以及一鍵加群的兩種方法

開啟QQ臨時會話

使用WPA介面,無需加其為好友就能和其進行會話

  1. Tencent mTencent =Tencent.createInstance(Config.TENCENT_APPID, getApplicationContext());
  2. WPA mWPA = mWPA =new WPA(this, mTencent.getQQToken());
  3. int ret = mWPA.startWPAConversation(getActivity(), qqNum,"");
  4. // ret為0表示成功打開了手機QQ的會話視窗,其他則為錯誤。

Android端一鍵加群

  1. /****************
  2. *
  3. * 發起新增群流程。群號:aaa(104784562) 的 key 為: sJFXu6TS1Rq1ppK4PCyMUIfeQjILjACK
  4. * 呼叫 joinQQGroup(sJFXu6TS1Rq1ppK4PCyMUIfeQjILjACK) 即可發起手Q客戶端申請加群 aaa(104784562)
  5. *
  6. * @param key 由官網生成的key
  7. * @return 返回true表示呼起手Q成功,返回fals表示呼起失敗
  8. ******************/
  9. publicboolean joinQQGroup(String key){
  10. Intent intent =newIntent();
  11. intent
    .setData(Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D"+ key));
  12. // 此Flag可根據具體產品需要自定義,如設定,則在加群介面按返回,返回手Q主介面,不設定,按返回會返回到呼起產品介面 //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
  13. try{
  14. startActivity(intent);
  15. returntrue;
  16. }catch(Exception
    e){
  17. // 未安裝手Q或安裝的版本不支援
  18. returnfalse;
  19. }
  20. }

另外,我們還以直接用網頁的程式碼來新增群,比如

  1. String groupUrl ="http://shang.qq.com/wpa/qunwpa?idkey=08a1f0506dba9816a94666c8ba3591090b396e31d3dc54daf3b5167b1c29ac2a";
  2. Intent intent =newIntent(this,JoinGroupQQActivity.class);
  3. intent.putExtra(JOIN_GROUP_QQ_URL, groupUrl);
  4. startActivity(intent);
  1. publicclassJoinGroupQQActivityextendsActivity{
  2. publicstaticfinalString JOIN_GROUP_QQ_URL ="joinGroupQQUrl";
  3. @SuppressLint("SetJavaScriptEnabled")
  4. @Override
  5. protectedvoid onCreate(Bundle savedInstanceState){
  6. super.onCreate(savedInstanceState);
  7. WebView webView =newWebView(this);
  8. setContentView(webView);
  9. webView.getSettings().setJavaScriptEnabled(true);
  10. Intent intent = getIntent();
  11. webView.loadUrl(intent.getStringExtra(JOIN_GROUP_QQ_URL));
  12. }
  13. }

這樣也起到了相同的效果。