我正在尝试在 Android Studio 中创建一个 TWA 应用程序,该应用程序可能适用于我们所有的域并在它们之间提供无缝导航,但没有想法。问题是——当在一个域内浏览一切正常时,手机上的“返回”按钮会返回到之前浏览过的页面。但是一旦您切换到另一个域,应用程序似乎会重新初始化,并且“返回”按钮不会返回到前一个域的页面。相反,它缩小了应用程序...
所有域都在各自的文件夹中包含数字资产文件,指纹没问题,应用程序与每个单独的域完美配合,但在尝试通过链接从一个域传递到另一个域时,它仍然像您刚刚打开它一样。
所有域都添加到<data>
Intent-filter 下的单独标签中,其中包含action.view
和类别DEFAULT
以及BROWSABLE
清单。尝试将资产报表中的关系添加到每个资产报表中,但没有获得预期结果的运气。
也许有人可以让它工作?任何意见,将不胜感激!
谢谢!
我愚蠢的新代码块
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.domain.newsapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true">
<meta-data
android:name="asset_statements"
android:resource="@string/asset_statements" />
<activity
android:name="android.support.customtabs.trusted.LauncherActivity"
android:theme="@style/Theme.LauncherActivity"
android:label="@string/app_name">
<meta-data
android:name="android.support.customtabs.trusted.DEFAULT_URL"
android:value="https://sub1.domain.ru/" />
<meta-data
android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR"
android:resource="@color/colorPrimary" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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="sub1.domain.ru"/>
<data android:scheme="https" android:host="sub2.domain.ru"/>
<data android:scheme="https" android:host="sub3.domain.ru"/>
</intent-filter>
</activity>
</application>
</manifest>
res\values\strings.xml
<resources>
<string name="app_name">MyApp</string>
<string name="asset_statements">
[{
\"relation\": [\"delegate_permission/common.handle_all_urls\"],
\"target\": {
\"namespace\": \"web\",
\"site\": \"https://sub1.domain.ru\"}
},{
\"relation\": [\"delegate_permission/common.handle_all_urls\"],
\"target\": {
\"namespace\": \"web\",
\"site\": \"https://sub2.domain.ru\"}
},{
\"relation\": [\"delegate_permission/common.handle_all_urls\"],
\"target\": {
\"namespace\": \"web\",
\"site\": \"https://sub3.domain.ru\"}
}]
</string>
</resources>
res\values\styles.xml
<resources>
<!-- Base application theme. -->
<style name="Theme.LauncherActivity" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowAnimationStyle">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
构建.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "ru.domain.newsapp"
minSdkVersion 16
targetSdkVersion 28
versionCode 2
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.release
}
buildTypes {
release {
minifyEnabled false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:+'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.github.GoogleChrome.custom-tabs-client:customtabs:91b4a1270b'
}
UPD 从文件中添加了代码
似乎我所说的这种行为不是重新初始化,而是覆盖了另一个子域内容而不是默认打开但没有像已安装 PWA 那样的操作栏,这导致无法关闭此覆盖以返回的问题以前的域...我真的希望这可以像普通的浏览器选项卡一样在同一个窗口中打开每个链接...