安卓:从网页唤醒APP

从网页打开APP,如果没有安装就进行下载。

安卓AndroidMainfext.xml

在要启动的activity下面添加一个intent-filter。

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:host="splash" android:scheme="vchao" />
       </intent-filter>

html 网页

<!doctype html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black"/>

        <title>唤醒APP</title>
        <meta id="viewport" name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,minimal-ui">
    </head>
    <body>
        <div>
            <a id="J-call-app" href="javascript:;" class="label">立即打开&gt;&gt;</a>
            <input id="J-download-app" type="hidden" name="storeurl" value="http://m.chanyouji.cn/apk/chanyouji-2.2.0.apk">
        </div>

        <script> (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); })() </script>
    </body>
</html>

如果需要传参数。

在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);  
     }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是你的春哥!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值