Android開啟QQ臨時會話以及一鍵加群的兩種方法
阿新 • • 發佈:2019-01-31
開啟QQ臨時會話
使用WPA介面,無需加其為好友就能和其進行會話
Tencent mTencent =Tencent.createInstance(Config.TENCENT_APPID, getApplicationContext());
WPA mWPA = mWPA =new WPA(this, mTencent.getQQToken());
int ret = mWPA.startWPAConversation(getActivity(), qqNum,"");
// ret為0表示成功打開了手機QQ的會話視窗,其他則為錯誤。
Android端一鍵加群
/****************
*
* 發起新增群流程。群號:aaa(104784562) 的 key 為: sJFXu6TS1Rq1ppK4PCyMUIfeQjILjACK
* 呼叫 joinQQGroup(sJFXu6TS1Rq1ppK4PCyMUIfeQjILjACK) 即可發起手Q客戶端申請加群 aaa(104784562)
*
* @param key 由官網生成的key
* @return 返回true表示呼起手Q成功,返回fals表示呼起失敗
******************/
publicboolean joinQQGroup(String key){
Intent intent =newIntent();
intent
// 此Flag可根據具體產品需要自定義,如設定,則在加群介面按返回,返回手Q主介面,不設定,按返回會返回到呼起產品介面 //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
try{
startActivity(intent);
returntrue;
}catch(Exception
// 未安裝手Q或安裝的版本不支援
returnfalse;
}
}
另外,我們還以直接用網頁的程式碼來新增群,比如
String groupUrl ="http://shang.qq.com/wpa/qunwpa?idkey=08a1f0506dba9816a94666c8ba3591090b396e31d3dc54daf3b5167b1c29ac2a";
Intent intent =newIntent(this,JoinGroupQQActivity.class);
intent.putExtra(JOIN_GROUP_QQ_URL, groupUrl);
startActivity(intent);
publicclassJoinGroupQQActivityextendsActivity{
publicstaticfinalString JOIN_GROUP_QQ_URL ="joinGroupQQUrl";
@SuppressLint("SetJavaScriptEnabled")
@Override
protectedvoid onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
WebView webView =newWebView(this);
setContentView(webView);
webView.getSettings().setJavaScriptEnabled(true);
Intent intent = getIntent();
webView.loadUrl(intent.getStringExtra(JOIN_GROUP_QQ_URL));
}
}
這樣也起到了相同的效果。