一個app打開另外一個app的指定頁面方法 有如下幾種 android
一、經過包名、類名app
二、經過intent的 actionspa
三、經過Urlcode
方案一、component
ComponentName componentName = new ComponentName("com.example.bi", "com.example.bi.SplashActivity");//這裏是 包名 以及 頁面類的全稱
Intent intent = new Intent(); intent.setComponent(componentName); intent.putExtra("type", "110");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
1.在Activity上下文以外啓動Activity須要給Intent設置FLAG_ACTIVITY_NEW_TASK標誌,否則會報異常。
2.加了該標誌,若是在同一個應用中進行Activity跳轉,不會建立新的Task,只有在不一樣的應用中跳轉纔會建立新的Task
方案二、blog
在目標Activity的配置文件中添加具體的actionget
<!--ACTION啓動配置--> <intent-filter> <action android:name="com.example.bi" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>
Intent intent = new Intent();
intent.setAction("com.example.bi"); intent.putExtra("type", "110");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
方案三、it
<!--URL啓動啓動配置-->
<intent-filter>
<data
android:host="com.example.bi" android:path="/cyn" android:scheme="csd" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter>
Intent intent = new Intent();
intent.setData(Uri.parse("csd://com.example.bi/cyn?type=110")); intent.putExtra("", "");//這裏Intent固然也可傳遞參數,可是通常狀況下都會放到上面的URL中進行傳遞
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
判斷要打開的app是否安裝:io
public static boolean isApkInstalled(Context context, String packageName) {
if (TextUtils.isEmpty(packageName)) { return false; } try { ApplicationInfo info = context.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); return true; } catch (NameNotFoundException e) { e.printStackTrace(); return false; } }