android一個app打開另一個app的指定頁面


一個app打開另一個app的指定頁面方法 有以下幾種  

     1、通過包名、類名

     2、通過intent的 action

     3、通過Url

 

  方案1、

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

方案2、

在目標Activity的配置文件中添加具體的action

<!--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);

方案3、

<!--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是否安裝:

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; } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM