H5實現(xiàn)鏈接格式如下
<a href="[scheme]://[host]/[path]?[query]"> 喚起應(yīng)用 </a>
各個項目含義如下所示:
scheme:喚起協(xié)議 ※詳細后述
host: 喚起指定host
path: 協(xié)議路徑※沒有也可以
query: 一些參數(shù)※沒有也可以
APP實現(xiàn)
協(xié)議假設(shè)為:example://com.example.demo/app?name=zhangsan
AndroidManifest中添加配置
<activity android:name=".SchemeActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:scheme="example"
android:host="com.example.demo"
android:path="/app"/>
</intent-filter>
</activity>
DATA標簽中匹配原則如下:
android:scheme : 喚起協(xié)議
android:host : 喚起host猴贰,只有置頂?shù)膆ost才可被喚起
android:pathPrefix : 喚起的路徑,對路徑進一步的過濾
客戶端獲取參數(shù)的值
Uri uri = this.getIntent().getData();
String scheme=uri.getScheme();
String host=uri.getHost();
String path=uri.getPath();
String name=uri.getQueryParameter("name");
注意事項
無論是在哪個平臺的客戶端Android/IOS月而,在微信的平臺上訪問都有一個問題悴灵,那就是無法啟動客戶端左刽,這是微信為了安全性考慮的限制,android這邊屏蔽schema協(xié)議,除非公司是微信的伙伴加入了白名單才能