233
233
文章分类
常用标签

安卓通过scheme网页跳转app,没有打开就跳转谷歌
script代码

<script type="text/javascript">
        var timeout;
        function startApp(){
            var ifr = document.createElement('iframe');
            ifr.src = 'scheme://host'; // shoule configure at AndroidManifest.xml
            ifr.style.display = 'none';
            timeout = setTimeout(function(){
                location.href = 'http://www.google.com'; // 
            }, 800);
            
            document.addEventListener("webkitvisibilitychange", clean);
            document.addEventListener("visibilitychange", clean);
            window.addEventListener("pagehide",  clean),
            
            document.body.appendChild(ifr);
        
        }
        
        function clean() {
            clearTimeout(timeout);
        }
    </script>

网页代码

<a href="javascript:;" onclick="startApp()">Start App</a><br/>

androidmanifest代码

<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="host"
                    android:scheme="scheme" />
            </intent-filter>
暂无评论

添加新评论