一、url scheme协议格式:
一个完整的完整的 url scheme协议格式由scheme、host、port、path和query组成,其结构如下所示:
scheme://host:port/path?query
举例:
coolweather://com.coolWeather.android:8080/WeatherActivity?param1=flag1¶m2=flag2
coolweather://?param1=flag1¶m2=flag2
二、 配置步骤:
1、参照如下配置注册DemoActivity
<activity
android:name=".DemoActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<!--默认的Category-->
<category android:name="android.intent.category.DEFAULT" />
<!--指定该Activity能被浏览器安全调用-->
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="[自定义]"
android:path="[自定义]"
android:port="[自定义]"
android:scheme="[自定义]" />
</intent-filter>
</activity>
<!-- 举例
<data
android:host="com.coolweather.android"
android:path="/WeatherActivity"
android:port="8080"
android:scheme="coolweather" />
-->
2、通过scheme协议打开app
private void openOtherApp() {
//方法1
String uriString = "android://com.coolWeather.android:8080/WeatherActivity?param1=flag1¶m2=flag2";
Intent intent = new Intent();
intent.setData(Uri.parse(uriString));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
//方法2
String uriString2 = "android://com.coolWeather.android:8080/WeatherActivity?";
Intent int