您的位置:首页 > 移动开发

网页判断判断是否安装APP并启动,没有安装就跳转到下载页面

2016-01-20 11:39 726 查看
下面是测试网页的内容:

<html>

<head>

<script type="text/javascript">

//判断手机上是否安装了app,如果安装直接打开,如果没安装,跳转到下载页面

function openApp(url) {

var timeout, t = 1000, hasApp = true;

var openScript = setTimeout(function () {

if (!hasApp) {

var durl = "http:www.baidu.com";

window.location.href=durl;

}

document.body.removeChild(ifr);

}, 2000)

var t1 = Date.now();

var ifr = document.createElement("iframe");

ifr.setAttribute('src', url);

ifr.setAttribute('style', 'display:none');

document.body.appendChild(ifr);

timeout = setTimeout(function () {

var t2 = Date.now();

if (!t1 || t2 - t1 < t + 100) {

hasApp = false;

}

}, t);

}

</script>

</head>

<body >

<input type="hidden" id="downloadUrl" name="downloadUrl" value="http:www.baidu.com"/>

<div>

<a href="javascript:void(0);" onclick='openApp("zdykapphaoyuntao://");' >Client</a>

</div>

<br/>

</body>

</html>

客户端以android举例:需要在AndroidManifest.xml文件启动activity下面加入 <data android:scheme="zdykapphaoyuntao" />

这样配置好后就在可以启动的activity里面拿到各种需要的数据:如下

Intent intent = getIntent();

Uri data = intent.getData();

if (null != data) {

String host = data.getHost();

String path = data.getPath();

String query = data.getQuery();

if (host.equals("productdetail")) {// 商品详情

intent = new Intent(ActWelcomeNow.this, ActGoodsDetail.class);

intent.putExtra(Contant.NAME, query);

ActWelcomeNow.this.startActivity(intent);

ActWelcomeNow.this.finish();

} else if (host.equals("shopindex")) {// 店铺首页

intent = new Intent(ActWelcomeNow.this, ActShopIndex.class);

intent.putExtra(Contant.NAME, query);

ActWelcomeNow.this.startActivity(intent);

ActWelcomeNow.this.finish();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: