android一个app打开另外一个app的指定页面

一个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; } }
相关文章
相关标签/搜索