#网页端
点击一个按钮来发送一个自定义scheme协议
例如:
startApp:function(url){
window.location = "app://main?param"+url
}
点击跳转到APP的按钮触发startApp方法
#scheme协议介绍
一个完整的完整的URI scheme协议格式由scheme、host、port、path和query组成,其结构如下所示:
<scheme>://<host>:<port>/<path>?<query>
APP端
<!--注册scheme-->
<intent-filter>
<!--必有项-->
<action android:name="android.intent.action.VIEW"/>
<!--表示该页面可以被隐式调用,必须加上该项-->
<category android:name="android.intent.category.DEFAULT"/>
<!--BROWSABLE指定该Activity能被浏览器安全调用-->
<category android:name="android.intent.category.BROWSABLE"/>
<!--协议部分-->
<!--声明自定义scheme,类似于http, https-->
<data android:scheme="app"
android:host="main"/>
</intent-filter>
取出数据
Intent intent = getIntent();
if (intent != null) {
Uri data = intent.getData();
if (null != data){
String host = data.getHost();
String scheme = data.getScheme();
String path = data.getPath();
//网页端定义的参数key值
String param = data.getQueryParameter("param");
String dataString = "host:"+host+"\n"+
"scheme:"+scheme+"\n"+
"path:"+path+"\n"+
"param:"+param+"\n";
if (dataString != null) {
Toast.makeText(this, dataString, Toast.LENGTH_LONG).show();
}
}
}
好了,这既是一个简单的网页唤醒APP的操作了,有不懂得地方可以在下方评论,看到了会及时回复