intent 高級篇

打開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實現(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();
    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容