Comments (7)
I have the same issue. After digging around, I found that every notifications are reusing the same PendingIntent. That is why they pass the same data stored with intent.putExtra().
This solution solves the problem: https://stackoverflow.com/questions/7370324/notification-passes-old-intent-extras
For a quick fix, edit NotificationIntentAdapter.java from this
public static PendingIntent createPendingNotificationIntent(Context appContext, Intent intent, PushNotificationProps notification) {
intent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle());
return PendingIntent.getService(appContext, PENDING_INTENT_CODE, intent, PendingIntent.FLAG_ONE_SHOT);
}
to this
public static PendingIntent createPendingNotificationIntent(Context appContext, Intent intent, PushNotificationProps notification) {
intent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle());
int uniqueInt = (int) (System.currentTimeMillis() & 0xfffffff);
return PendingIntent.getService(appContext, uniqueInt, intent, PendingIntent.FLAG_ONE_SHOT);
}
The concept is to pass a different "requestCode" for each notification.
With this, when having multiple notifications, PendingNotifications promise result will give the data for the notification that you pressed.
from react-native-notifications.
@swellingt0n You cannot fix the issue within JS code. Fortunately, you can override the PushNotification java class.
Follow these steps: https://github.com/wix/react-native-notifications/wiki/Android:-Layout-Customization
In MyPushNotification class, override getCTAPendingIntent() method.
public class MyPushNotification extends PushNotification {
public MyPushNotification(Context context, Bundle bundle, AppLifecycleFacade appLifecycleFacade, AppLaunchHelper appLaunchHelper, JsIOHelper jsIoHelper) {
super(context, bundle, appLifecycleFacade, appLaunchHelper, jsIoHelper);
}
@Override
protected PendingIntent getCTAPendingIntent() {
final Intent cta = new Intent(mContext, ProxyService.class);
return CustomNotificationIntentAdapter.createPendingNotificationIntent(mContext, cta, mNotificationProps);
}
}
CustomNotificationIntentAdapter class (copy over from the original NotificationIntentAdapter.java and modify createPendingNotificationIntent())
public class CustomNotificationIntentAdapter {
private static final String PUSH_NOTIFICATION_EXTRA_NAME = "pushNotification";
public static PendingIntent createPendingNotificationIntent(Context appContext, Intent intent, PushNotificationProps notification) {
intent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle());
int uniqueInt = (int) (System.currentTimeMillis() & 0xfffffff);
return PendingIntent.getService(appContext, uniqueInt, intent, PendingIntent.FLAG_ONE_SHOT);
}
}
from react-native-notifications.
You may want to read the first paragraphs of the following page before implementing this.
https://developer.android.com/reference/android/app/PendingIntent
From this page "A common mistake people make is to create multiple PendingIntent objects with Intents that only vary in their "extra" contents, expecting to get a different PendingIntent each time. This does not happen. The parts of the Intent that are used for matching are the same ones defined by Intent#filterEquals(Intent). If you use two Intent objects that are equivalent as per Intent#filterEquals(Intent), then you will get the same PendingIntent for both of them."
Also "A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it. This means that, even if its owning application's process is killed, the PendingIntent itself will remain usable from other processes that have been given it. If the creating application later re-retrieves the same kind of PendingIntent (same operation, same Intent action, data, categories, and components, and same flags), it will receive a PendingIntent representing the same token if that is still valid, and can thus call cancel() to remove it."
My interpretation of this is that your android application is holding onto every "unique" pending intent combination you ever created without cancelling it. This is true even if your applications process is killed and restarted. It may be the case that android has some way of killing the older pending intents after some period of time. I do not know if it does or does not.
from react-native-notifications.
@re7eal Thanks for the insightful response! Is there any way to achieve this within the JS code, or is the only alternative to override the class within the android/ folder of the project, to avoid issues with updates to the node_modules content?
from react-native-notifications.
@re7eal Thank you, closing this for now.
from react-native-notifications.
Wanted to leave an update for anyone with this issue, finally got around to implementing @re7eal 's solution and it worked perfectly.
from react-native-notifications.
Thanks, @re7eal perfect solution!
from react-native-notifications.
Related Issues (20)
- "$" getting copied HOT 1
- Code that setting NotificationChannel sound on Android might lead unexpected consequences HOT 1
- Application does not trigger registerNotificationOpened when it is closed, only when it is in the background.
- I can't get notifications to open my app HOT 1
- How to undo `Notifications.registerRemoteNotifications()` ? HOT 3
- Minification failure with R8: Compilation failed for ReactAppLifecycleFacade$1 in react-native-notifications
- Not receiving any notification on iOS release mode only HOT 1
- Huawei push notification in library
- dexOptions is obsolete
- Feature request: add support for iOS simulator push notifications HOT 3
- Does FCM work with this package in iOS? HOT 4
- Handle callback when notification in background / terminate app HOT 3
- When I click on the notification on my android app, entire app reloads HOT 4
- Question - is there support for the new RN architecture? HOT 1
- Suggestion - documentation update HOT 1
- Feature request: support for dynamic Live Activities on IOS
- What about the wiki for integration with react notification?
- registerRemoteNotificationsRegistrationDenied being called even when "Allowed" clicked
- is it possible to send local notification when App is closed
- [Question]: Grouping on iOS
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-notifications.