![](/img/trans.png)
[英]How can I get my Android app to always open in Chrome or another browser that supports TWA?
[英]How can we please add subdomains from same provider to TWA based android app?
我正在嘗試為單個 TWA 應用程序添加子域。 我已經完成了從網站到應用程序的資產鏈接。 即使鏈接完成,我每次都能看到 URL 欄。
字符串.xml
<resources>
<string name="app_name">XXXX </string>
<string name="asset_statements" translatable="false">
[{
\"relation\": [\"delegate_permission/common.handle_all_urls\"],
\"target\": {
\"namespace\": \"web\",
\"site\": \"https://www.xxxx.com\"}
},{
\"relation\": [\"delegate_permission/common.handle_all_urls\"],
\"target\": {
\"namespace\": \"web\",
\"site\": \"https://www.abcd.xxxx.com\"}
}]
</string>
</resources>
Android清單
<activity
android:name="android.support.customtabs.trusted.LauncherActivity">
<!-- Edit android:value to change the url opened by the TWA -->
<meta-data
android:name="android.support.customtabs.trusted.DEFAULT_URL"
android:value="https://www.xxxx.com" />
<meta-data
android:name="android.support.customtabs.trusted"
android:value="https://www.abcd.xxxx.com" />
//在 android 清單中添加了意圖過濾器
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE"/>
<!-- Edit android:host to handle links to the target URL-->
<data
android:scheme="https"
android:host="www.xxxx.com"/>
<data
android:scheme="https"
android:host="www.abcd.xxxx.com"/>
我可以看到沒有 url 欄的 www.xxxx.com 但對於 www.abcd.xxxx.com 我可以看到 URL 欄。
https://developers.google.com/digital-asset-links/tools/generator
我使用以下鏈接檢查了鏈接,它返回主機已授予應用深度鏈接
我一直在努力嘗試自己解決此問題,盡管我還沒有答案,但我已經取得了足夠的進展,可以在TWA內更改子域,而沒有顯示網址欄。
我的第一步是將資產報表設置為具有通配符:
<string name="asset_statements">
[{
\"relation\": [\"delegate_permission/common.handle_all_urls\"],
\"target\": {
\"namespace\": \"android_app\",
\"site\": \"https://*.newvote.org\"}
}]
</string>
然后,我能夠將android.support.customtabs.trusted.DEFAULT_URL
元數據設置為子域上的任何URL,並且它可以與位於Web服務器上的當前assetasses.json文件一起愉快地工作。 但是,我無法在應用程序中更改子域/ URL,因為這會打開URL欄。
在進行測試時,我開始嘗試使用不同的URL(我們的Web應用程序具有許多子域),並且我注意到先前測試的域開始起作用。 似乎通過將URL設置為DEFAULT_URL
,應用程序以某種方式將它們緩存為受信任的。 我嘗試卸載應用程序並清除我的Chrome緩存,但是這種情況仍然存在,因此我不確定這是如何工作的。
我可以肯定地為您確認的是該設置:
<meta-data android:name="android.support.customtabs.trusted" android:value="@string/app_url" />
將無法正常工作,您正在嘗試在類名稱上設置元數據,並且當我探索android.support.customtabs.trusted
類時,我可以看到DEFAULT_URL
是唯一用於URL定義的屬性。
到目前為止,我的結論是:我認為您不需要多個asset_statement。 我不認為您需要多個元數據字段,也不相信在intent-filter中設置多個data:host字段會達到預期的效果。 我認為最重要的是,目前尚沒有支持在TWA中處理子域的方法。
剛剛確認,當我測試並安裝該應用程序的不同版本時,這種對可信URL的神奇緩存正在發生。 在另一台設備上安裝最新版本將還原為單個受信任的URL,並且子域導航失敗。
您應該將assetlinks.json文件添加到您的應用可能訪問的每個子域中
因此所有這些鏈接應返回資產文件
https://www.xxxx.com/.well-known/assetlinks.json
https://www.abcd.xxxx.com/.well-known/assetlinks.json
還要確保它遵循這些准則 。
200個響應和內容類型的application/json
重定向將不起作用
為了讀取狀態欄,您需要檢查以下兩個步驟:
您應該為每個子域添加/.well-known/assetlinks.json
端點。 請參閱參考鏈接: https : //developer.android.com/training/app-links/verify-site-associations#publish-json
在 android 清單中,您應該添加帶有主機值通配符的意圖過濾器。 注意:主機值應嚴格以 * 開頭,並且不包含架構,例如 https://
<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="https" android:host="*.xxxx.com"/> </intent-filter>
您不必在asset_statments
明確指定所有子域。 在那里有你的默認值就足夠了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.