DeepLink 就是在網(wǎng)頁端調(diào)起APP內(nèi)部的頁面,為了達(dá)到更好的用戶體驗(yàn)凤跑,這個(gè)鏈接主要運(yùn)用在移動(dòng)廣告平臺(tái),廣告主在投放的過程中,用戶在某個(gè)app或者網(wǎng)頁上看見了某款產(chǎn)品的廣告幻妓,用戶通過點(diǎn)擊這個(gè)鏈接,會(huì)自動(dòng)的調(diào)起相應(yīng)的APP劫拢,直達(dá)產(chǎn)品內(nèi)部詳情頁肉津,提升app的喚醒和購買率。
在Android M之后熟吏,Google推出了App Links, 就是http或者h(yuǎn)ttps的常規(guī)鏈接距糖,比如:http://zt.jd.com/ad/appjump.shtml?turl=http%3A%2F%2Fsale.jd.com%2Fm%2Fact%2FOFtlMS3Ksg.html&platform=1
如上兩種links大多數(shù)瀏覽器都能夠很好的處理,有部分瀏覽器也不能很好的支持牵寺。這里主要說的是webview的操作方式悍引。
其實(shí)很簡單,就是判斷scheme是不是http或者h(yuǎn)ttps, 如果是的帽氓,就讓webview自己去處理趣斤,如果是第三方的scheme就用Intent去處理。
核心代碼如下:
webview.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.e("IntentUtils","shouldOverrideUrlLoading");
/*
if(adIntentUtils.shouldOverrideUrlLoadingByApp(view,url))
{
return true;
}*/
if(isThirdPartyScheme(Uri.parse(url)))
{
try {
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
intent.addFlags(268435456);
AdActivity.this.startActivity(intent);
return true;
} catch (Exception e) {
return true;
}
}
Log.e("IntentUtils","false");
return false;
}
});
private boolean isThirdPartyScheme(Uri uri) {
String scheme = uri.getScheme();
return (scheme.equals("http") || scheme.equals("https")) ? false : true;
}
具體的GitHub Demo