從一個APP啟動另一個APP的Activity的方法
1、通過自定義action啟動
這種方式只需要在代碼中設(shè)置一個action即可, 系統(tǒng)會自動過濾去找到這個action所對應(yīng)的Activity
當(dāng)前APP的代碼
Intent intent = new Intent();
//這里是采用的自定義action
intent.setAction("transBundle.app");
startActivity(intent);
待啟動APP 的activity在AndroidManifest.xml中的配置
<!- 需要配置對應(yīng)的自定義action->
<activity
android:name=".MyActivity"
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action android:name="transBundle.app"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
2、通過在Intent中通過指定包名和類名來查找
直接在當(dāng)前APP中寫以下代碼,即可打開指定APP的activity
ComponentName componetName = new ComponentName(
"com.poynt.weibo", //這個是另外一個應(yīng)用程序的包名
"com.poynt.weibo.ui.IndexActivity"); //這個參數(shù)是要啟動的Activity的全路徑名
try {
Intent intent = new Intent();
intent.setComponent(componetName);
startActivity(intent);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "可以在這里提示用戶沒有找到應(yīng)用程序,或者是做其他的操作!", 0).show();
}
3、通過scheme啟動
其實這個方法和方法1類似, 只是說增加了scheme參數(shù), scheme更多的用于 在網(wǎng)頁或者H5上來啟動我們的APP, 比如在手機官網(wǎng)上通過scheme可以直接打開我們的app, 這里我們只是從APP用scheme啟動另一個APP
當(dāng)前應(yīng)用的代碼:
Uri uri = Uri.parse("app://my.test");
Intent intent = new Intent("transBundle.app", uri);
startActivity(intent);
待打開APP的AndroidManifest配置文章來源:http://www.zghlxwxcb.cn/news/detail-474665.html
<activity
android:name=".MyActivity"
android:label="service"
android:exported="true">
<intent-filter>
<action android:name="transBundle.app"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="app" android:host="my.test"/>
</intent-filter>
</activity>
其中app類似于http://www.baidu.com中的 http, 表示傳輸協(xié)議; my.test類似于www.baidu.com, 表示主機名文章來源地址http://www.zghlxwxcb.cn/news/detail-474665.html
到了這里,關(guān)于從一個APP啟動另一個APP的activity的方式的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!