从网页打开APP,如果没有安装就进行下载。
安卓AndroidMainfext.xml
在要启动的activity下面添加一个intent-filter。
html 网页
唤醒APP(function(){
/*获取UA标识,并转为小写*/
var ua = navigator.userAgent.toLowerCase();
var t;
var config = {
/*scheme:必须*/
scheme_IOS: 'vchao://',
scheme_Adr: 'vchao://splash',
download_url: document.getElementById('J-download-app').value,
timeout: 600
};
function openclient() {
var startTime = Date.now();
var ifr = document.createElement('iframe');
/*通过UA标识,判断是否是苹果系统*/
ifr.src = ua.indexOf('os') > 0 ? config.scheme_IOS : config.scheme_Adr;
ifr.style.display = 'none';
document.body.appendChild(ifr);
var t = setTimeout(function() {
var endTime = Date.now();
if (!startTime || endTime - startTime < config.timeout + 200) {
window.location = config.download_url;
} else {
}
}, config.timeout);
window.onblur = function() {
clearTimeout(t);
}
}
window.addEventListener("DOMContentLoaded", function(){
document.getElementById("J-call-app").addEventListener('click',openclient,false);
}, false);
})()
如果需要传参数。
在html网页中直接拼接参数。
vchao://splash/?arg0=marc&arg1=xie
在唤醒的activity页面做参数的接收。
Uri uri = getIntent().getData();
if (uri != null) {
String test1 = uri.getQueryParameter("arg0");
String test2 = uri.getQueryParameter("arg1");
tv.setText(test1 + test2);
}