打開QQ 并與對應(yīng)QQ號聊天
String url="mqqwpa://im/chat?chat_type=wpa&uin=12345";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
今天試圖開發(fā)一款A(yù)pps實(shí)現(xiàn)跳轉(zhuǎn)到某些Apps的某些intent 結(jié)果失敗了 可是tasker就可以 不解
Intent in = new Intent();
ComponentName componetName = new ComponentName("com.tencent.mm", "com.tencent.mm.plugin.sns.ui.SnsCommentUI");
in.setComponent(componetName);
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(in);
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dao.myintent/com.dao.myintent.MainActivity}: java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10000000 cmp=com.tencent.mm/.plugin.sns.ui.SnsCommentUI } from ProcessRecord{43196d78 27266:com.dao.myintent/u0a92} (pid=27266, uid=10092) not exported from uid 10087
原因在于需要在app2里面聲明
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
不然就不能成功
打開其他APP的方法
// 通過包名獲取要跳轉(zhuǎn)的app,創(chuàng)建intent對象
Intent intent = getPackageManager().getLaunchIntentForPackage("com.tencent.mm");
// 這里如果intent為空,就說名沒有安裝要跳轉(zhuǎn)的應(yīng)用嘛
if (intent != null) {
// 這里跟Activity傳遞參數(shù)一樣的嘛,不要擔(dān)心怎么傳遞參數(shù),還有接收參數(shù)也是跟Activity和Activity傳參數(shù)一樣
intent.putExtra("key", "value");
startActivity(intent);
} else {
// 沒有安裝要跳轉(zhuǎn)的app應(yīng)用苔货,提醒一下
Toast.makeText(getApplicationContext(), "no install!", Toast.LENGTH_LONG).show();
}