![](/img/trans.png)
[英]Using wildcard in host attribute for android 12 AppLinks does not work ( android:host="*.example.com" does not work but www.example.com does )
[英]How does Google App Indexing handle https://www.example.com vs https://example.com
我剛剛完成了為網站的Android應用設置App Indexing的工作,並根據https://中指定的說明通過了https://www.example.com/test和https://example.com/test進行了一些測試。 /developers.google.com/app-indexing/android/test (使用Android Studio測試網址)
這是我在Android清單中的意圖過濾器:
<intent-filter android:label="@string/filter_title_default">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"
android:host="example.com"
android:pathPrefix="/test" />
</intent-filter>
我注意到https://www.example.com/test失敗,但https://example.com/test卻沒有。 除了為www.example.com/test指定另一個意圖過濾器之外,我該如何解決?
據我所知,應該將每個主機添加到新的意圖過濾器中。 您可以參考此文檔以獲取更多信息。
干杯,MB
您可以為意圖過濾器指定多個數據元素,以用於活動需要處理的所有URL。
要處理到您的域的www和非www鏈接,您可以將意圖過濾器更改為:
<intent-filter android:label="@string/filter_title_default">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"
android:host="example.com"
android:pathPrefix="/test" />
<data android:scheme="https"
android:host="www.example.com"
android:pathPrefix="/test" />
</intent-filter>
或者,要處理example.com和任何子域,可以在主機的開頭添加通配符:
<intent-filter android:label="@string/filter_title_default">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"
android:host="example.com"
android:pathPrefix="/test" />
<data android:scheme="https"
android:host="*.example.com"
android:pathPrefix="/test" />
</intent-filter>
另外,如果要匹配所有域URL,則必須完全刪除pathPrefix屬性,因為將其設置為“ /”不能正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.