2014-09-23 198 views
1

我嘗試添加在Android深度鏈接,所以在我的網頁我更換一個iframe這樣Android的深層鏈接

<iframe scrolling="no" width="1" height="1" style="display: none;" 
src="myscheme://post/5002"></iframe> 

,並在我的manifest.xml(Android應用程序)

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme"> 
    <activity 
     android:name=".MyActivity" 
     android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

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

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

      <data android:scheme="myscheme" /> 
     </intent-filter> 
    </activity> 
</application> 

但當我打開網頁在鉻它沒有顯示「打開與」對話框來選擇我的應用程序

我測試了深度連接android使用此和對話框出現

adb shell am start -W -a android.intent.action.VIEW -d "myscheme://whatever" 
+0

您正在測試哪種Android版本? – dirkoneill 2014-10-17 19:17:41

回答

2

Chrome for Android版本25及更高版本的功能稍有變化。通過設置iframe的src屬性不再可能啓動Android應用程序。應使用「意圖:」語法代替

意圖://主機/#意圖;方案=協議;包= com.domain.apppackage;端

用於基於意圖的URI的基本語法如下:

意圖: HOST/URI路徑//可選主機
#Intent;
package = [string];
action = [string];
category = [string];
component = [string];
scheme = [string];
end;

請檢查該page

1

iframe解決方案不再有效使用Chrome的最新版本。 Anas說你需要用「intent:// ..:」地址創建一個鏈接。用戶還需要執行一些操作才能打開鏈接。

爲了解決這個問題,我創建了一個鏈接縮短工具。你可以在這裏使用它: http://www.uppurl.com/

此工具將創建一個基於用戶瀏覽器的相應深層鏈接的照顧。我建議你使用它,因爲它爲你解決了很多工作,你甚至不需要修改或有一臺服務器。

0

不知道,但你可以嘗試使用JavaScript來代替IFRAME:

location.href = "myscheme://post/5002" 

而且,只是爲了測試是否它的工作或根本沒有,你可以嘗試設置主機和路徑數據中的元素意圖過濾器:

<data android:scheme="myscheme" 
        android:host="post" 
        android:pathPrefix="502">