天天看點

如何通過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

繼續閱讀