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