版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012162503/article/details/51852201
近期由于项目需要,通过浏览器打开本地app应用。经过多方的查询反复的尝试和阅读。总结出来。有价值的知识的分享出来。虽说不是很难。
第一步:
写好相关的js方便调取如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=1" name="viewport" />
<title>打开本地app</title>
</head>
<body>
<div>测试</div>
<iframe src="open://app/goods?id=2456677&type=02" frameborder="0"></iframe>
</body>
</html>
把这个保存存成html文件放到服务器外网能够访问就行。
第二步
打开本地页面的activity 里面增加如下代码
<activity
android:name="com.simo.main"
android:launchMode="singleTask"
android:screenOrientation="portrait" >
<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:host="app"
android:pathPrefix="/goods"
android:scheme="open" />
</intent-filter>
</activity>
其中android:host="app" android:pathPrefix="/goods" android:scheme="open" 这里面的参数对应的是 js iframe 里面的open://app/goods 要求对应起来。
等这些都写好了就已经成功一大半了。
第三步:在需要你刚刚加入上面代码的activity 的onCreate 添加如下代码?
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Intent i_getvalue = getIntent();
String action = i_getvalue.getAction();
if(Intent.ACTION_VIEW.equals(action)){
Uri uri = i_getvalue.getData();
if(uri != null){
String id = uri.getQueryParameter("id");
String type= uri.getQueryParameter("type");
System.out.println("id ===="+id )
System.out.println("type===="+type )
}
}
}
完成上述大功告成!哈哈哈!打开应用的速度杠杠的。赶快用起来吧!
有不明白的欢迎留言!
我们一起共同进步!表示谢谢!如果有技术问题欢迎
加入我的QQ群 285526158.
喜欢的可以关注微信公众号,哪里每天都会推荐一篇开源项目Git项目地址在里欢迎订阅