需求
为了提高转化率,需要在分享页面,直接调起原生app,如果原生没有安装,跳转到下载页面
京东
普通浏览器
一般是通过Scheme跳转
网页端
function isInstalled(){
var the_href=$(".down_app").attr("href");//获得下载链接
window.location.href="apps custom url schemes";//打开某手机上的某个app应用
setTimeout(function(){
window.location.href=the_href;//如果超时就跳转到app下载页
},500);
}
原生端
内部用的是Arouter进行分发
<activity android:name=".routeInterceptor.SchemeFilterActivity">
<!-- Schame -->
<intent-filter>
<data
android:host="m.gxyj.com"
android:scheme="native" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<!-- App Links -->
<!-- Android M 开始全面支持,需要网页端有个签名验证(Android M + 验证 需要使用https) -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="m.gxyj.com"
android:scheme="http" />
<data
android:host="m.gxyj.com"
android:scheme="https" />
</intent-filter>
</activity>
经测试,可以成功,但是存在一个兼容性问题,部分机型页面会显示所请求的地址有错等,没能跳转到app下载页面。网上有解决办法说的是:将setTimeOut的时间缩短,我这里设置的是500ms,觉得时间有点长了,那么我就设置30ms;
微信浏览器
微信浏览器(同QQ),屏蔽了使用Scheme方法调起本地App,据说只有少部分白名单(深度合作,类似京东)
下面提供两种降级解决方案:
应用宝
直接跳转到应用宝页面,应用宝能够判断用户是否安装,如果安装了,直接应用点击打开,未安装,直接在应用宝里面去下载App
缺点:只能打开App首页,无法具体到具体的页面,还有一个就是要跳到应用宝界面,始终感觉有点不爽
优点:不用考虑兼容性问题
诱导用户用浏览器打开(类似淘宝)
ZAKER
缺点:需要多操作一步,有些用户可能不太愿意
优点:可以跳转到任意界面