2017-02-09 69 views
0

我希望在點擊具有特定自定義方案的鏈接時啓動我的應用。 但它只能從亞行可與:Android應用鏈接僅適用於adb

./adb shell a start -a Android.Intent.Action.VIEW -d "ghd://whateversite.com"

當點擊一個鏈接,或者URL在瀏覽器中直接寫入它不工作。

我使用:

<activity 
     android:name=".link.LaunchActivity" 
     android:theme="@android:style/Theme.NoDisplay"> 
     <intent-filter> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <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:scheme="ghd" /> 
     </intent-filter> 
    </activity> 

回答

0

的意圖過濾器設置android:host

<activity 
    android:name=".link.LaunchActivity" 
    android:noHistory="true" 
    android:theme="@android:style/Theme.NoDisplay"> 
    <intent-filter android:autoVerify="true"> 
     <action android:name="android.intent.action.VIEW" /> 

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

     <data android:scheme="ghd" android:host="whateversite.com" /> 
    </intent-filter> 
</activity> 
+0

嗨,謝謝你的迴應。但是,「whateversite.com」實際上可能是無法企及的)唯一會始終存在的部分就是方案ghd。 – RominaV

0

嘗試從<intent-filter/>刪除autoVerify=true。正如documentation說:

當機器人:autoVerify屬性存在,安裝您的應用程序將導致系統嘗試驗證與您的所有應用程序的意圖過濾器的網頁的URI相關聯的所有主機。只有在您的應用程序成功驗證清單中聲明的​​所有應用程序鏈接模式時,系統纔會將您的應用程序視爲指定URI模式的默認處理程序。

由於您沒有添加任何主機,這可能是它不工作的原因。

+0

你說得對,它沒有意義。我刪除它,但行爲是一樣的。謝謝! – RominaV

+0

這很奇怪,因爲我現在在我身邊有完全相同的東西,它只是工作...同樣在你的例子中,你使用的是「mdw」方案,你的adb命令使用「ghd」,但我不認爲這是這個問題,我可能會誤會。 – maxoumime

+0

這是:P在你的情況下,它只是當你直接在瀏覽器中寫入時才起作用? – RominaV