切换风格

默认Lavender Sky Flowers Wizard Snow Beige California City Dragon Black London Sunset glow Pink Cloud

14

主题

367

积分

0

精华

用户组 

易积分
4466
热心
1
好评
4
[免费]打开网站检测APP并提示打开[复制链接]
发表于 2018-5-19 08:49:24 | 显示全部楼层 |阅读模式
打开网站判断是否安装APP,如果已经安装则提示打开,适用于Android、iPhone等设备,亲测可用!

Scheme定义Activity

1)在androidmanifest.xml中定义scheme

<!-- 启动页 --><activity    android:name="com.qiyuan.congmingtou.activity.SplashActivity"    android:label="@string/app_name">    <intent-filter>        <action android:name="android.intent.action.MAIN" />        <category android:name="android.intent.category.LAUNCHER" />    </intent-filter>    <!-- 要想在别的App上能成功调起App,必须添加intent过滤器 -->    <intent-filter>        <!-- 协议部分,随便设置 -->        <data android:scheme="cmt" android:host="splash"/>        <!-- 下面这几行也必须得设置 -->        <category android:name="android.intent.category.DEFAULT" />        <category android:name="android.intent.category.BROWSABLE" />        <action android:name="android.intent.action.VIEW" />    </intent-filter></activity>这样我们便定义了能够接受scheme请求的activity实例,当网页或者是android代码发送这种规则scheme的请求的时候就能够吊起SplashActivity了。

2).网页中Html代码和js代码

<!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>this's a demo</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(){
                var ua = navigator.userAgent.toLowerCase();
                var t;
                var config = {
                    /*scheme:必须*/
                    scheme_IOS: 'IfInstalledCongMingTou://congmingtou',
                    scheme_Adr: 'cmt://splash',
                    download_url: document.getElementById('J-download-app').value,
                    timeout: 600
                };

                function openclient() {
                    var startTime = Date.now();

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


                    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>


注:本文非原创,转自:CSDN,不知道站长让不让贴原创链接,所以就不发原创链接了,免得删帖了,看论坛有过相关内容出售过,下载了测试下,不知道是不是我兼容问题,我这没效果,特意在网上找了找文章,分享给大家,有能力的搞个类库给大家也是稳稳的!
易如意中文编程学习交流论坛有你更精彩~
回复

使用道具 举报

3

主题

345

积分

0

精华

用户组 

易积分
849
热心
0
好评
0
QQ

活跃会员

发表于 2018-5-19 09:50:56 | 显示全部楼层
此帖仅作者可见
易如意中文编程学习交流论坛有你更精彩~

使用道具 举报

6

主题

704

积分

0

精华

用户组 

易积分
4411
热心
0
好评
2
发表于 2018-5-19 10:08:46 | 显示全部楼层
此帖仅作者可见
易如意中文编程学习交流论坛有你更精彩~

使用道具 举报

3

主题

141

积分

0

精华

用户组 

易积分
33
热心
0
好评
0
发表于 2018-5-19 10:57:11 | 显示全部楼层
此帖仅作者可见
易如意中文编程学习交流论坛有你更精彩~

使用道具 举报

1

主题

293

积分

0

精华

用户组 

易积分
312
热心
0
好评
0
发表于 2018-5-19 11:18:52 | 显示全部楼层
此帖仅作者可见
易如意中文编程学习交流论坛有你更精彩~

使用道具 举报

7

主题

259

积分

0

精华

用户组 

易积分
1223
热心
0
好评
0
发表于 2018-5-19 17:32:00 | 显示全部楼层
此帖仅作者可见
易如意中文编程学习交流论坛有你更精彩~

使用道具 举报

1

主题

53

积分

0

精华

用户组 

易积分
36
热心
0
好评
0
发表于 2018-5-20 12:46:11 | 显示全部楼层
此帖仅作者可见
易如意中文编程学习交流论坛有你更精彩~

使用道具 举报

0

主题

92

积分

0

精华

用户组 

易积分
397
热心
0
好评
0
发表于 2019-11-21 16:18:32 来自手机 | 显示全部楼层
此帖仅作者可见
易如意中文编程学习交流论坛有你更精彩~

使用道具 举报

QQ|sitemap|免责声明|RGB颜色对照表|手机版|小黑屋| 易如意 - E4A中文编程学习交流论坛

GMT+8, 2024-4-20 17:47 , Processed in 0.051176 second(s), 36 queries .

Powered by Discuz! X3.4

© 2001-2018 eruyi.cn

返回顶部