首页 > 解决方案 > 当用户单击推送通知时打开 TWA 应用程序而不是 Web 应用程序

问题描述

当前行为:当用户单击推送通知时,Web 应用程序打开,即使 TWA 应用程序安装在 android 手机中。

预期行为:当用户单击推送通知时,我想打开 TWA(受信任的网络活动)应用程序。

我正在使用 Firebase 进行推送通知

我只是使用 google 的示例 repo ( https://github.com/GoogleChromeLabs/svgomg-twa ) 作为我的基础并覆盖它。

当用户单击通知时我尝试打开的 URL 类似于https://dev.example.com/

这是我的 AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/appName"
        android:supportsRtl="true"
        android:theme="@style/Theme.LauncherActivity">

        <meta-data
            android:name="asset_statements"
            android:resource="@string/assetStatements" />
        <meta-data
            android:name="cros_web_alternative"
            android:value="@string/crosLaunchUrl" />

        <activity android:name="android.support.customtabs.trusted.LauncherActivity"
            android:label="@string/appName">
            <meta-data android:name="android.support.customtabs.trusted.DEFAULT_URL"
                android:value="@string/launchUrl" />

            <meta-data
                android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR"
                android:resource="@color/colorPrimary" />

            <meta-data
                android:name="android.support.customtabs.trusted.NAVIGATION_BAR_COLOR"
                android:resource="@color/navigationColor" />

            <meta-data android:name="android.support.customtabs.trusted.SPLASH_IMAGE_DRAWABLE"
                android:resource="@drawable/splash"/>

            <meta-data android:name="android.support.customtabs.trusted.SPLASH_SCREEN_BACKGROUND_COLOR"
                android:resource="@color/backgroundColor"/>

            <meta-data android:name="android.support.customtabs.trusted.SPLASH_SCREEN_FADE_OUT_DURATION"
                android:value="@integer/splashScreenFadeOutDuration"/>

            <meta-data android:name="android.support.customtabs.trusted.FILE_PROVIDER_AUTHORITY"
                android:value="@string/providerAuthority"/>

            <meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />

            <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="@string/hostName"/>
            </intent-filter>

        </activity>

        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="@string/providerAuthority"
            android:grantUriPermissions="true"
            android:exported="false">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
        </provider>

        <service
             android:name="android.support.customtabs.trusted.TrustedWebActivityService"
             android:enabled="@bool/enableNotification"
             android:exported="@bool/enableNotification">

             <intent-filter>
                 <action android:name="android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE"/>
                 <category android:name="android.intent.category.DEFAULT"/>
             </intent-filter>
         </service>

    </application>
</manifest>

标签: javascriptpush-notificationprogressive-web-appstrusted-web-activitytwa

解决方案


这似乎是 Chrome 80 中引入的错误。

检查此铬错误以获取更多详细信息: https ://bugs.chromium.org/p/chromium/issues/detail?id=1052288


推荐阅读