0

I am working on a Flutter app. I need to integrate notifications using firebase cloud messaging. I am able to send notifications both in foreground and background. But, in case of background, the onLaunch and onResume are not getting triggered.

This is my JSON notification object:

{
   "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",
   }
}

And here is the code for all the callbacks:

_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
  },
);

I am getting this log when the app is in background:

W/FirebaseMessaging(12077): Notification Channel set in AndroidManifest.xml has not been created by the app. Default value will be used.

E/FirebaseMessaging(12077): Notification pending intent canceled

But the channel id is already set in AndroidManifest.xml

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

And intent-filter is there too:

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

I don't know what I am missing here. Any help is would be great. Thank you!

Bhawna Saroha
  • 603
  • 1
  • 11
  • 28

1 Answers1

0

Add the below code in AndroidManifest.xml. Don't delete the other one just add this one.

<intent-filter>
    <action android:name="OPEN_ACTIVITY_1" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Vignesh
  • 215
  • 2
  • 6