ben-xD / push

Push notifications in Flutter without firebase_messaging.
https://pub.dev/packages/push
36 stars 22 forks source link

[Android] I get push notifications several times #60

Closed Pluxury closed 1 month ago

Pluxury commented 1 month ago

The problem only occurs on Android. On iOS, the push handler is called only once, as it should

Steps to reproduce:

  1. Added push to pubspec.yaml and called push get
  2. Added Google services.json in android/app
  3. Set up settings.gradle and app/build.gradle
  4. I am sending a push notification

Current behavior:

  Push.instance.addOnBackgroundMessage((message) {
      print('RemoteMessage received while app is in background:\n'
          'RemoteMessage.Notification: ${message.notification} \n'
          ' title: ${message.notification?.title}\n'
          ' body: ${message.notification?.body}\n'
          'RemoteMessage.Data: ${message.data}');
    });

It is called several times

Here is my my console output

RemoteMessage received while app is in background:

I/flutter ( 8428): RemoteMessage.Notification: null 
I/flutter ( 8428):  title: null
I/flutter ( 8428):  body: null
I/flutter ( 8428): RemoteMessage.Data: {NotificationAction: 1}
W/mportal.patien( 8428): Accessing hidden method Landroid/os/WorkSource;->add(I)Z (greylist,test-api, reflection, allowed)
W/mportal.patien( 8428): Accessing hidden method Landroid/os/WorkSource;->add(ILjava/lang/String;)Z (greylist,test-api, reflection, allowed)
W/mportal.patien( 8428): Accessing hidden method Landroid/os/WorkSource;->get(I)I (greylist, reflection, allowed)
W/mportal.patien( 8428): Accessing hidden method Landroid/os/WorkSource;->getName(I)Ljava/lang/String; (greylist, reflection, allowed)
I/flutter ( 8428): RemoteMessage received while app is in background:
I/flutter ( 8428): RemoteMessage.Notification: null 
I/flutter ( 8428):  title: null
I/flutter ( 8428):  body: null
I/flutter ( 8428): RemoteMessage.Data: {NotificationAction: 1 }

And the situation is similar for push in foregroun

Expected behavior: The push handler is called only once