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

     

  • 相关阅读:
    SpringCloud学习教程
    Google浏览器插件推荐
    谷歌身份验证器使用
    js控制某个div在页面加载完成5秒后隐藏
    通过城市联动实时将地址显示到text中
    百度地图通过地址查询并且定位
    yii2.0验证码的两种实现方式
    yii2.0 中数据查询中 or、in、between 及session的使用
    Calling unknown method: appmodulesmobilecontrollersCompanyController::redirect()
    页面权限跳转
  • 原文地址:https://www.cnblogs.com/bimingcong/p/10409914.html
Copyright © 2020-2023  润新知