Android FCM 推送通知未在单击时启动应用程序

问题描述 投票:0回答:1

我通过 FCM 旧版 api 发送通知,如下所示:

// POST https://fcm.googleapis.com/fcm/send
{
    "to": "<device-token>",
    "notification": {
        "title": "Test!",
        "body": "testing",
        "mutable_content": true,
        "sound": "Tri-tone",
        "click_action": "https://example.com/1234"
    }
}

清单:

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

  <uses-permission android:name="android.permission.INTERNET" />

  <application 
    android:name=".MainApplication" 
    android:label="@string/app_name" 
    android:icon="@mipmap/ic_launcher" 
    android:roundIcon="@mipmap/ic_launcher_round" 
    android:allowBackup="false" 
    android:theme="@style/AppTheme">

    <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@mipmap/ic_launcher" />
    <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/light" />
    <meta-data
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="@string/default_notification_channel_id" />

    <activity
      android:name=".MainActivity"
      android:label="@string/app_name"
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
      android:launchMode="singleTask"
      android:windowSoftInputMode="adjustResize"
      android:screenOrientation="portrait"
      android:exported="true">
      <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="example.com" />
      </intent-filter>
    </activity>
  </application>

  <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
</manifest>

正在接收通知,但单击它时不会启动应用程序。

有趣的是,如果我自己启动应用程序,则会在反应本机链接事件回调中收到通知。

所以除了应用程序启动之外,一切都正常!令人沮丧。

注意;深层链接在“click_action”测试中使用相同的 url,使用

adb shell am start -W -a android.intent.action.VIEW -d "https://example.com/some-deep-link" cx.myapp.android

谢谢!

android firebase react-native push-notification firebase-cloud-messaging
1个回答
0
投票

问题可能是为活动创建的意图过滤器,它应该是这样的:

<activity
        android:name="com.your_activity_name">

        <intent-filter>
            <action android:name="com.your activity page"></action>
            <category android:name="android.intent.category.DEFAULT"/>                
        </intent-filter>
    </activity>

如您所见,键 click_action 的值应该与意图过滤器

<action android:name="the same value">
中的值相同。

© www.soinside.com 2019 - 2024. All rights reserved.