All Notifications of the App getting cleared when I click one notification (Android)
This issue happens only on android, when I have more than one notification for the App and if I click any one, then all other notifications of the App is getting cleared automatically. What could be the problem or should I add any flags etc ?
Checked on Android 4.4 and 5.0 React-Native 0.43.0-rc.4 React-Navigation 1.0.0-beta.11
In your custom notification class extending PushNotification, returned by getPushNotification(...), override function onOpened, so it looks like this:
@Override
public void onOpened() {
digestNotification();
}
@Lastin thanks for the reply I will try your solution and respond back.
@ravirajn22 You will have to make one more change to make your notifications work in that way however.
In com.wix.reactnativenotifications.core.NotificationIntentAdapter function createPendingNotificationIntent uses flag PendingIntent.FLAG_ONE_SHOT when calling PendingIntent.getService which causes the pending intent with same hash (see) to not be able to run activity more than once.
Solution:
Use PendingIntent.FLAG_UPDATE_CURRENT flag instead
This caused an issue for me. When I received multiple notifications, tapping on any notification would always bring up most recently received notification. Instead, I followed the advice here: https://stackoverflow.com/questions/28091784/multiple-pending-intents
So now my createPendingNotifications method in core/NotificationIntentAdapter looks like this:
public static PendingIntent createPendingNotificationIntent(Context appContext, Intent intent, PushNotificationProps notification) {
intent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle());
intent.setAction(Long.toString(System.currentTimeMillis()));
return PendingIntent.getService(appContext, PENDING_INTENT_CODE, intent, PendingIntent.FLAG_ONE_SHOT);
}
And it seems to work as intended.
@kaloncheung124 and @Lastin is there a possibility of solving this problem through java, but without making any changes to the library directly. Like overriding functions of library etc. I thought of overriding getCTAPendingIntent() where createPendingNotificationIntent() is called, but don't know if it creates any side effects.
@ravirajn22 Maybe my comment in the following issue can help you : https://github.com/wix/react-native-notifications/issues/143#issuecomment-361987796
@ravirajn it looks like @mfekim has a great solution that doesn't require overwriting the library. If you still end up wanting to modify the library though, here's the commit with my full solution: https://github.com/kaloncheung124/react-native-notifications/commit/1f10e052a526dcdecdaa000e32ca087f77936049
@kaloncheung124 and @mfekim I ended up overriding the getCTAPendingIntent() and onOpened(). Thanks for your help.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.
The issue has been closed for inactivity.