打開QQ 并與對應QQ號聊天
String url="mqqwpa://im/chat?chat_type=wpa&uin=12345";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
今天試圖開發一款Apps實現跳轉到某些Apps的某些intent 結果失敗了 可是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的方法
// 通過包名獲取要跳轉的app,創建intent對象
Intent intent = getPackageManager().getLaunchIntentForPackage("com.tencent.mm");
// 這里如果intent為空,就說名沒有安裝要跳轉的應用嘛
if (intent != null) {
// 這里跟Activity傳遞參數一樣的嘛,不要擔心怎么傳遞參數,還有接收參數也是跟Activity和Activity傳參數一樣
intent.putExtra("key", "value");
startActivity(intent);
} else {
// 沒有安裝要跳轉的app應用,提醒一下
Toast.makeText(getApplicationContext(), "no install!", Toast.LENGTH_LONG).show();
}