evollu / react-native-fcm

react native module for firebase cloud messaging and local notification
MIT License
1.73k stars 682 forks source link

Notifications stop displaying on Android 8 and 8.1 #933

Closed tss101 closed 6 years ago

tss101 commented 6 years ago
  1. React-Native version 0.51, react-native-fcm version (14.1.2 sdk-26 branch)
  2. Nokia 8 (Android 8.1) and Nokia 7 Plus (Android One 8.0.0)
  3. App is not running or running in background (user bug report, user was not sure)
  4. Firebase version 11.8.0

Hi,

I have an an released with react-native-fcm, and I'm getting user reports that notifications work for a while, then just stop. I finally managed to get a log report of one of the incidents, and the message that comes up is this:

05-07 17:18:01.849 27551 27551 W GCM     : broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=to.synced.synced (has extras) }

Once the message comes up, it continues coming, and no further notifications arrive

Googling around it seems this crops up most often when the app is force killed by a battery saving mechanism more common in phones like the OnePlus 3T.

But in this case there is no battery saving being applied, at some point this message pops up and the notifications stop (along with the foreground service the app runs while it is closed).

I've also tried the same code on Android 5.1 and it runs without issue

I'm using custom notifications for Android, with the following format

{
            "custom_notification": {
                "channel":"default",
                "id":id,
                "number": number,
                "body": body,
                "big_text": body,
                "title": title,
                "icon":"ic_notif",
                "priority":"high",
                "sound":"default",
                "show_in_foreground": showinfg
                }
}
evollu commented 6 years ago

this seems to be more of a firebase ticket com.google.android.c2dm.intent.RECEIVE is not an intent this package listens to or send out.

tss101 commented 6 years ago

Thanks, though I'm not sure why notifications in our app are getting killed, since we only use the react-native-fcm package. We're pretty certain this is the event that's responsible for stopping the notifications, but we're not sure why it might be related to com.google.android.c2dm.intent.RECEIVE.

evollu commented 6 years ago

https://stackoverflow.com/questions/39480931/error-broadcast-intent-callback-result-cancelled-forintent-act-com-google-and

or this

https://stackoverflow.com/questions/44847835/android-fcm-not-receiving-notifications-when-app-is-removed-from-background/45810771#45810771

does this help?

tss101 commented 6 years ago

Many thanks @evollu

I'd taken a look at the first one before but I don't think applies here. I've received a few more reports, and some of them didn't receive the:

05-07 17:18:01.849 27551 27551 W GCM : broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=to.synced.synced (has extras) }

message. Also this is pretty much on stock Android, so swiping the app away shouldn't result in force kill like on the OnePlus 3T. However it might be related to Android 8's new battery saving features.

The second link is interesting:

notification payload can be send using data tag or notification tag. using data tag it will trigger the FirebaseMessagingService onMessageReceived method. it will not work on some devices, when an app is in the background.

We're still trying to figure out when exactly notifications stop working, but it is quite possible they stop delivering while the app is in the background, and don't restart until the app is swiped away and restarted.

It's quite hard to catch however as it happens infrequently (why we think it's related to the battery saving Android 8 features). Currently we're sending notifications every five minutes to some test devices, and once they're stop appearing on the device they don't reappear until the app is reopened.

evollu commented 6 years ago

I think it might have to do battery saving as well. Can you try native firebase SDK example for Android and see if you can reproduce the issue?

tss101 commented 6 years ago

Sure, I've installed it, and will try sending regular notifications to see if they stop at the same time

tss101 commented 6 years ago

Actually maybe the best strategy is to send a notification to Firebase after my app stops receiving them

tss101 commented 6 years ago

And see if they arrive

tss101 commented 6 years ago

One possible solution might be not send my notifications as data, but instead as standard notifications, which would then get handled by Firebase regardless of whether the app is running or not.

The downside of this approach is that they can't be shown in the foreground anymore

tss101 commented 6 years ago

Digging through the logs I did come across this. Is number supposed to be a float?

05-07 22:57:01.280  6508  9943 W Bundle  : Key number expected Double but value was a java.lang.Integer.  The default value 0.0 was returned.
05-07 22:57:01.281  6508  9943 W Bundle  : Attempt to cast generated internal exception:
05-07 22:57:01.281  6508  9943 W Bundle  : java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double
05-07 22:57:01.281  6508  9943 W Bundle  :      at android.os.BaseBundle.getDouble(BaseBundle.java:1069)
05-07 22:57:01.281  6508  9943 W Bundle  :      at android.os.BaseBundle.getDouble(BaseBundle.java:1051)
05-07 22:57:01.281  6508  9943 W Bundle  :      at com.evollu.react.fcm.SendNotificationTask.doInBackground(SendNotificationTask.java:77)
05-07 22:57:01.281  6508  9943 W Bundle  :      at com.evollu.react.fcm.SendNotificationTask.doInBackground(SendNotificationTask.java:36)
05-07 22:57:01.281  6508  9943 W Bundle  :      at android.os.AsyncTask$2.call(AsyncTask.java:333)
05-07 22:57:01.281  6508  9943 W Bundle  :      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
05-07 22:57:01.281  6508  9943 W Bundle  :      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
05-07 22:57:01.281  6508  9943 W Bundle  :      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
05-07 22:57:01.281  6508  9943 W Bundle  :      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
05-07 22:57:01.281  6508  9943 W Bundle  :      at java.lang.Thread.run(Thread.java:764)
evollu commented 6 years ago

what does SendNotificationTask.java:77 have?

AFAIK, JS should pass double/float into native.

tss101 commented 6 years ago

.setNumber((int)bundle.getDouble("number"))

tss101 commented 6 years ago

I pass in 3 as number in my test cases

tss101 commented 6 years ago

from FCM

evollu commented 6 years ago

fixed in v15.0.1

jurajkrivda commented 6 years ago

After update on 15.0.1 app crashed

evollu commented 6 years ago

@jurajkrivda step to reproduce?

tss101 commented 6 years ago

Thanks @evollu. Could you update the sdk-26 branch (I'm using that branch)?

About the originally posted issue, I tracked down where the app was being force stopped. The notifications were stopping because of the force stop.

evollu commented 6 years ago

@tss101 I've merged changes into sdk-26

tss101 commented 6 years ago

Many thanks @evollu!