android使用Scheme进行唤起三方app

Aapp唤起Bapp

Aapp

Intent intent =new Intent(Intent.ACTION_VIEW,
Uri.parse(“myapp://cb”));//输入你们协定的Scheme

//intent.putExtra(“code”, code);可以传参

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//如果是唤起三方app,加入次方法,如果是在Aapp直接打开三方页面则不需要次方法

// 启动目标应用

startActivity(intent);

Bapp

首先在manifest.xml中加入

<activity

android:name="接收的activity"

android:screenOrientation="portrait"

android:exported="true"

android:theme="@style/SplashAppTheme">

然后在你接收的activity中处理

Intent routerIntent = getIntent();

Uri intentUri = routerIntent.getData();

//如果是三方进入

if (Intent.ACTION_VIEW.equals(routerIntent.getAction())) {

//在里面处理你想处理的就可以了

}

Android app 使用scheme可以让其他应用程序或者网页链接打开你的应用程序,并且可以携带参数,实现应用程序之间的跳转和交互。以下是Android app 使用scheme的步骤: 1. 在AndroidManifest.xml文件中注册scheme。例如,你可以在<activity>标签中添加一个<intent-filter>标签,并且在<intent-filter>标签中添加一个<data>标签,如下所示: ```xml <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="myapp" android:host="openactivity" /> </intent-filter> </activity> ``` 2. 在应用程序中处理scheme。在你的MainActivity中,你可以通过以下代码来处理scheme: ```java @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); String action = intent.getAction(); Uri data = intent.getData(); if (data != null) { String host = data.getHost(); if (host.equals("openactivity")) { //处理scheme参数,打开指定的Activity } } } ``` 3. 在其他应用程序或者网页中使用scheme打开你的应用程序。例如,你可以在浏览器中输入“myapp://openactivity”来打开你的应用程序并且跳转到指定的Activity。 注意事项: 1. 必须在<intent-filter>标签中添加<category android:name="android.intent.category.BROWSABLE" />,否则无法在浏览器中打开应用程序。 2. scheme参数区分大小写。 3. 如果你的应用程序中有多个Activity需要处理scheme,需要在<intent-filter>标签中分别添加<data>标签,每个<data>标签的scheme和host必须不同。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值