react-native-notifications icon indicating copy to clipboard operation
react-native-notifications copied to clipboard

All Notifications of the App getting cleared when I click one notification (Android)

Open ravirajn22 opened this issue 9 years ago • 10 comments

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

ravirajn22 avatar Sep 18 '17 09:09 ravirajn22

In your custom notification class extending PushNotification, returned by getPushNotification(...), override function onOpened, so it looks like this:

@Override
public void onOpened() {
    digestNotification();
}

m-makuch avatar Oct 23 '17 12:10 m-makuch

@Lastin thanks for the reply I will try your solution and respond back.

ravirajn22 avatar Oct 24 '17 06:10 ravirajn22

@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

m-makuch avatar Oct 26 '17 09:10 m-makuch

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 avatar Dec 19 '17 02:12 kaloncheung124

@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 avatar Jan 30 '18 10:01 ravirajn22

@ravirajn22 Maybe my comment in the following issue can help you : https://github.com/wix/react-native-notifications/issues/143#issuecomment-361987796

mfekim avatar Jan 31 '18 16:01 mfekim

@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 avatar Jan 31 '18 17:01 kaloncheung124

@kaloncheung124 and @mfekim I ended up overriding the getCTAPendingIntent() and onOpened(). Thanks for your help.

ravirajn22 avatar Feb 01 '18 06:02 ravirajn22

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.

stale[bot] avatar Jul 24 '19 21:07 stale[bot]

The issue has been closed for inactivity.

stale[bot] avatar Aug 01 '19 00:08 stale[bot]