1

I implemented firebase cloud messaging and followed the following tutorial https://www.youtube.com/watch?time_continue=304&v=2TSm2YGBT1s&feature=emb_logo. And I got it working for the most part. Whenever the app is in the background or closed I get a notification and it will open the app and execute the callback onResume or onLaunch.

But I can't seem to get the onMessage callback to work. Whenever the app is in the foreground and I send the notification, the onMessage isn't called? I get the following log to my console

E/FlutterFcmService(18141): Fatal: failed to find callback
W/FirebaseMessaging(18141): Unable to log event: analytics library is missing
W/FirebaseMessaging(18141): Unable to log event: analytics library is missing

I have not seen onBackgroundMessage being called either.

Notification Service

class CloudMessagingService extends NotificationService
{
  final FirebaseMessaging firebaseMessaging = FirebaseMessaging();

  CloudMessagingService()
  {
    if(Platform.isIOS)
      firebaseMessaging.requestNotificationPermissions(IosNotificationSettings());

    firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        print('I have a cloud messaging message yay');
        print('onMessage: $message');
      },
      onBackgroundMessage: (Map<String, dynamic> message) async {
        print('onBackgroundMessage: $message');
      },
      onLaunch: (Map<String, dynamic> message) async {
        print('onLaunch: $message');
      },
      onResume: (Map<String, dynamic> message) async {
        print('onResume: $message');
      },
    );
  }

  Future<void> sendNotificationToGroup(GroupModel group, NotificationType type)
  {
    print('Send ${type.valueString} notification to ${group.id}');
    return null;
  }
}

I am testing this on a android emulator with the Pixel 3XL

1 Answer 1

2

So I took a closer look at the documentation and found

Note: When you are debugging on Android, use a device or AVD with Google Play services. Otherwise you will not be able to authenticate.

After switching to a device that does have the playstore support the onMessage callback was called!

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.