天天看点

如何通过Html网页调用本地安卓app并且获取从html传递过来的数据

业务场景:使用友盟分享到微信的链接,用户点击该链接进入网页之后,选择浏览器打开之后会提示打开本地应用,此时要保证从app分享到微信再从微信唤醒本地app之后打开的页面是否一致,下面是相关截图

1,首先需要给启动Activity添加过滤条件

<category android:name="android.intent.category.BROWSABLE" />  //必须配置,重点,这个表示可以通过浏览器打开的类型应用
<category android:name="android.intent.category.DEFAULT" />  
 <action android:name="android.intent.action.VIEW" /> 
           
<data android:scheme="http" android:host="www.baidu.com"  /> //scheme配置协议 host配置主机 还可以配置路径pathprefix

           

2,在启动页面通过隐式意图获取html传递过来的数据

Intent intent = getIntent();  
Uri uri = intent .getData();  
String xxx= uri.getQueryParameter(键值);  
String xxx= uri.getQueryParameter(键值);  
           

获取到传递过来的数据之后就可以跳转到指定的页面或者其他的一些操作了

3,以上只针对安卓原生浏览器,像第三方的浏览器是不起作用的,可能是因为安全考虑被拦截了吧

参考文章:https://blog.csdn.net/u012600955/article/details/60987610

https://blog.csdn.net/qq1073273116/article/details/52398856

继续阅读