項目要求url打開android應用

首先準備Android這一塊的;

1. 在項目的清單配置文件的啓動Activity的下添加:

 <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />

 <!-- android:pathPrefix="自己定義/自己定義"   自己定義部分可以按需定義  然後給到服務端-->
                <data
                    android:pathPrefix="自己定義/自己定義"  <應用名稱/open>
                    android:scheme="自己定義" /><例: myApp>

  </intent-filter>


2. 在自己項目中(按照自己需要  再合適的地方獲取   一般在主activity的onCreate()方法中獲取)  添加:

 public static void getData() {
try {
Uri uriData = this.getIntent().getData();  
String data = uridata.getQueryParameter("data");//data是url傳給客戶端的參數   如果不需要  可以不添加次方法
} catch (Exception e) {
e.printStackTrace();
}
}

3.url中添加(Android 和 IOS):
 var ifr = document.createElement('iframe');
                ifr.src ="jdz48077888youjoy://data=<?php echo (isset($_GET['自己定義'])?$_GET['自己定義']:0) ?>";
                ifr.style.display = 'none';
                document.body.appendChild(ifr);
var isAndroid = navigator.userAgent.match('Android');
        if (isAndroid) {
                var ifr = document.createElement('iframe');
                ifr.src ="自己定義:/自己定義/自己定義?data=<?php echo (isset($_GET['data'])?$_GET['data']:0) ?>";
                ifr.style.display = 'none';
                document.body.appendChild(ifr);

        };



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章