TWA 在触发 chrome 意图时自动关闭

问题描述

我想要的是 CustomTWAActivity 不关闭并继续运行。

我有一个启动 TWA(基于 CCT 协议的可信 Web 活动)的 MainActivity。我已经使用自定义类扩展了 TWA 启动器,以便我可以覆盖它的 onNewIntent 方法并做一些工作。

在主活动中,我像这样调用 CustomTWAActivity:

val intent = Intent(this,CustomTWAActivity::class.java)
    val args = call.arguments as String?
    if (args != null && args.isNotEmpty()) {
        intent.data = Uri.parse(args)
        startActivity(intent)
        isTWAOpen = true
    }

TWA 打开一个网站,然后依次触发 CustomTWAActivity 接收到的 chrome 意图。意图过滤器添加到清单文件中的活动中,如下所示:

<activity
        android:launchMode="singleTask"
        android:name=".CustomTWAActivity">

        <!-- Edit android:value to change the url opened by the Trusted Web Activity -->
        <Meta-data
            android:name="android.support.customtabs.trusted.DEFAULT_URL"
            android:value="https://app.skillclash.com" />

        <Meta-data
            android:name="android.support.customtabs.trusted.ADDITIONAL_TRUSTED_ORIGINS"
            android:resource="@array/additional_trusted_origins" />

        <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="app.skillclash.com" />
        </intent-filter>
    </activity>

添加singleTask 的 launchMode,以便它在 onNewIntent 中接收 Intent,并且不会在堆栈中创建新的 Activity。

我在 CustomTWAActivity 的 onNewIntent 方法中接收到新意图,任务先完成,然后 TWA 自行关闭。意思是自动调用 CustomTWAActivity 完成的方法。并且控制返回到 MainActivity

这是如何覆盖 onNewIntent:

class CustomTWAActivity: LauncherActivity() {

override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    Log.i("intent in launcher",intent?.dataString?: "no intent data received")
    if (intent != null) {
        if (intent.action === Intent.ACTION_VIEW) {
            val value = intent.dataString
            TWAUtils.onNewIntentReceived(value)
        }
    }
}

}

我想要的是 CustomTWAActivity 不关闭并继续运行。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)