DeepLink 就是在网页端调起APP内部的页面,为了达到更好的用户体验,这个链接主要运用在移动广告平台,广告主在投放的过程中,用户在某个app或者网页上看见了某款产品的广告,用户通过点击这个链接,会自动的调起相应的APP,直达产品内部详情页,提升app的唤醒和购买率。
在Android M之前,deep link主要是scheme的形式,比如 openapp.jdmobile://virtual?params=%7B%22category%22%3A%22jump%22%2C%22des%22%3A%22jshopMain%22%2C%22shopId%22%3A%221000002700%22%2C%20%22M_sourceFrom%22%3A%20%22mxz%22%2C%20%22m_param%22%3A%7B%22jda%22%3A%22122270672.783316907.1510136158.1510136158.1510136159.2%22%2C%22jdv%22%3A%22122270672%7Cjdzt_refer_null%7Ct_232310336_1%7Cjzt-zhitou%7Cnttqewqnaaai6yjnfxqa%22%2C%22a%22%3A%22b%22%7D%2C%20%22SE%22%3A%22ADC_w55VSKmyMOL2Ziyo5%2BLMeheK6LaBBFp752owfvnjiLcAg6fsD%2Bp3t8E4JU%2BRkQeR7kr7kNG2FQ9E3Vn6iFdwT%2FECREg8BU26zxckPC44bniJDdjocC4C55c%2FpqnYsR0Ab9V3BZ1eo80JWXQMmk5M5yIJ1LQS%2BzwahakUQ04Yc9VWDzIhEQU9%2Fy6RfdqeoUtgyoajwqLwoon8IWLQaE2kIBHYr%2FLDsBO7E0UBqr3dfbS0gVEIBZlALCWSbNpxGh%2FamcetwEFVBSihGQMbAhgRlhOeillK9nKmxtyCpQgMT0sTjgIOBkE9MIHnL02c%2FsCJqkE44nWdR4W2C7OE08vvhBNBjkr0bhGpMNo5XexWkVW09tVEWslL2q%2FKdoiMAJVEk%2FzlXBJLIMFv5%2Fo41GWpGJ5DOzHsjANaQRD8hR5%2FcoGWRDeN5cywOH4Yyi4l%2BKy68USTOdeRT0IhHlU7i%2F0NdQ%3D%3D%22%2C%22qz_gdt%22%3A%22nttqewqnaaai6yjnfxqa%22%2C%22csrc%22%3A%22gdt%22%7D weixin://dl/moments有自己的scheme。
在Android M之后,Google推出了App Links, 就是http或者https的常规链接,比如:http://zt.jd.com/ad/appjump.shtml?turl=http%3A%2F%2Fsale.jd.com%2Fm%2Fact%2FOFtlMS3Ksg.html&platform=1
如上两种links大多数浏览器都能够很好的处理,有部分浏览器也不能很好的支持。这里主要说的是webview的操作方式。
其实很简单,就是判断scheme是不是http或者https, 如果是的,就让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