1. 程式人生 > >【Android】webview點選跳轉APP

【Android】webview點選跳轉APP

在AndroidMainfest檔案中的activity中新增:
<intent-filter>
                 <!--路徑匹配  協議://主機名:埠號/路徑-->
                <!--content://quanziben:8080/openapp-->
                <data
                    android:scheme="content"
                    android:host="quanziben"
                    android:port="8080"
                    android:path="/openapp"/>

                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

            </intent-filter>

html如下:

<html>
      <head>
          <meta charset="utf-8" />
      <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">          

      </head>
      <body>
        <a href="content://quanziben:8080/openapp" target="_self" id="taobao">開啟全資本</a>

            <script type="text/javascript">
            function applink(){  
                return function(){  
                    var clickedAt = +new Date;  
                     setTimeout(function(){
                         !window.document.webkitHidden && setTimeout(function(){
                               if (+new Date - clickedAt < 2000){  
                                   window.location = 'http://www.quanziben.com';  
                               }  
                         }, 500);       
                     }, 500)   
                };  
            }  
            document.getElementById("taobao").onclick = applink();  
            document.getElementById("trip").onclick = applink();  
            </script>   
    </body>
</html>