【问题标题】:Firebase: onLaunch and onResume not working on notificationsFirebase:onLaunch 和 onResume 无法处理通知
【发布时间】:2021-03-03 18:30:49
【问题描述】:

我正在开发一个 Flutter 应用程序。我需要使用 firebase 云消息来集成通知。我能够在前台和后台发送通知。但是,在后台的情况下,不会触发 onLaunch 和 onResume。

这是我的 JSON 通知对象:

{
   "sound": "default",
   "registration_ids": userToken,
   "collapse_key": "type_b",
   "priority": "high",
   "notification": {
     "title": 'New message',
     "body": messageContent,
   },
   "data": {
   "type": "message",
   "title": 'New message',
   "body": messageContent,
   "click_action": "FLUTTER_NOTIFICATION_CLICK",
   }
}

这里是所有回调的代码:

_firebaseMessaging.configure(
  onMessage: (Map<String, dynamic> message) async {
    print("onMessage called");
    if (message['data']['type'] == 'message') {
      print(message['data']['type']);
      setState(() {
        newMessage = true;
      });
    }
  },
  onLaunch: (Map<String, dynamic> message) async {
    print('onlaunch called');
    // open message screen
  },
  onResume: (Map<String, dynamic> message) async {
    print('onResume called');
    // open message screen
  },
);

当应用程序处于后台时,我会收到此日志:

W/FirebaseMessaging(12077):AndroidManifest.xml 中设置的通知通道尚未由应用创建。将使用默认值。

E/FirebaseMessaging(12077):通知未决意图已取消

但是频道ID已经在AndroidManifest.xml中设置了

<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id"/>

还有意图过滤器:

<intent-filter>
  <action android:name="FLUTTER_NOTIFICATION_CLICK" />
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

我不知道我在这里缺少什么。任何帮助都会很棒。谢谢!

【问题讨论】:

标签: android firebase flutter firebase-cloud-messaging


【解决方案1】:

在 AndroidManifest.xml 中添加以下代码。不要删除另一个,只需添加这个即可。

<intent-filter>
    <action android:name="OPEN_ACTIVITY_1" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

【讨论】:

    猜你喜欢
    • 2019-08-17
    • 2017-08-09
    • 1970-01-01
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    • 2018-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多