react-native-push-notification-CE
react-native-push-notification-CE copied to clipboard
[Android] onNotification not called when application is closed
Hi,
I'm trying to add a badge when I receive a notification on Android but I have an issue, indeed, the onNotification
is not triggered when app wasn't launched at all. So when I receive the first notification and the app is not launched, I can see in the Chrome debugger
that the app launches (silently, it doesn't open) but onNotification
is not triggered. After that, when I receive another notification and the app is already silently launched, then, the onNotification
is triggered...
For the record, I'm trying to PushNotification.setApplicationBadgeNumber()
each time I receive a notification but if onNotification
is not called the first time, I can't do it... I also tried to put:
console.log('appStart');
PushNotification.appStart();
in a setTimeout like this:
setTimeout(() => {
console.log('appStart');
PushNotification.appStart();
}, 10);
but then, the timeout is reached only when I manually launch the app...
If anyone has another solution to set the badge on Android even when I receive only one notification, please let me know! :)
RN VERSION: 0.55.3 LIB VERSION: Master (#767d043f15fe7daf8639b4a5fbcba6fca960d793) PHONE: Xiaomi Redmi Note 4X PLATFORM: Android
As far as I know the badge is set automatically using ShortcutBadger library, maybe it doesn't work on some devices. On my OnePlus 3 it didn't work.
But I already have the same issue that onNotification method is not called when opening a notification received.
Ok, I found out why onNotification
is not being called when the app is closed. As I was calling appStart
method just after starting the app but before the configure
method when the library pops the initial notification the onNotification
method is not yet defined, so the solution I found is to call appStart
method after the configure
method, that way onNotification is always called when opening the app from a push notification.
Maybe @calcazar can take a look if this is a proper solution or we should do anything else cleaner.
Any solution? I have the same problem