TWA(Trusted Web Activity) で BuildTypes によって表示するページを変更する
環境
macOS High Sierra - 10.13.6
Android Studio - 3.4
変更する方法
build.gradle に TWA の設定を debug、release それぞれ記述します
build.gradle
android {
...
buildTypes {
debug {
...
manifestPlaceholders = [
hostName : "*****",
defaultUrl : "debug用のURL",
assetStatements: '[{ "relation": ["delegate_permission/common.handle_all_urls"], ' +
'"target": {"namespace": "web", "site": "debug用のURL"}}]'
]
}
release {
...
manifestPlaceholders = [
hostName : "*****",
defaultUrl : "release用のURL",
assetStatements: '[{ "relation": ["delegate_permission/common.handle_all_urls"], ' +
'"target": {"namespace": "web", "site": "release用のURL"}}]'
]
}
}
}
AndroidManifest.xml の android.support.customtabs.trusted.DEFAULT_URL を build.gradle から取得するようにします
AndroidManifest.xml
<activity android:name="android.support.customtabs.trusted.LauncherActivity">
<meta-data android:name="android.support.customtabs.trusted.DEFAULT_URL"
android:value="${defaultUrl}" />
...
<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="https"
android:host="${hostName}"/>
</intent-filter>
</activity>
build.gradle
android {
...
buildTypes {
debug {
...
manifestPlaceholders = [
hostName : "*****",
defaultUrl : "debug用のURL",
assetStatements: '[{ "relation": ["delegate_permission/common.handle_all_urls"], ' +
'"target": {"namespace": "web", "site": "debug用のURL"}}]'
]
}
release {
...
manifestPlaceholders = [
hostName : "*****",
defaultUrl : "release用のURL",
assetStatements: '[{ "relation": ["delegate_permission/common.handle_all_urls"], ' +
'"target": {"namespace": "web", "site": "release用のURL"}}]'
]
}
}
}
AndroidManifest.xml
<activity android:name="android.support.customtabs.trusted.LauncherActivity">
<meta-data android:name="android.support.customtabs.trusted.DEFAULT_URL"
android:value="${defaultUrl}" />
...
<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="https"
android:host="${hostName}"/>
</intent-filter>
</activity>
debug、release を切り替えて実行してみて、表示されるページが変わっていたら対応完了です!
Author And Source
この問題について(TWA(Trusted Web Activity) で BuildTypes によって表示するページを変更する), 我々は、より多くの情報をここで見つけました https://qiita.com/koichi-ozaki/items/eb8143a1148508d688d1著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .