App启动另一个App的指定页面

原文链接: https://www.cnblogs.com/bimingcong/p/10409914.html

方案一: 通过包名类名

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

方案二:通过intent的 action

在目标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);

方案三:通过Uri

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

PS:
启动app之前要判断下是否有安装这个app可以参考下面的链接的第一步第三步

https://blog.csdn.net/qq_38287890/article/details/91416925

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值