-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notifee does not support extra params from Android intent back to JS #1081
Comments
FYI we had to implement a patch for this, we've added an extra private List<Bundle> fetchNotificationData(List<Bundle> aBundleList) {
NotificationManager notificationManager = (NotificationManager) getReactApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
StatusBarNotification[] activeNotifications = notificationManager.getActiveNotifications();
for (StatusBarNotification sbn : activeNotifications) {
Notification notification = sbn.getNotification();
Bundle extras = notification.extras;
if (extras != null) {
Bundle data = extras.getBundle("data");
if (data != null) {
for (Bundle originalBundle : aBundleList) {
Bundle originalNotificationBundle = originalBundle.getBundle("notification");
if (originalNotificationBundle != null && originalNotificationBundle.getString("id").equals(String.valueOf(sbn.getId()))) {
originalNotificationBundle.putBundle("data", data);
}
}
}
}
}
}
return aBundleList;
}
@ReactMethod
public void getDisplayedNotifications(Promise promise) {
Notifee.getInstance()
.getDisplayedNotifications(
(e, aBundleList) -> NotifeeReactUtils.promiseResolver(promise, e, fetchNotificationData(aBundleList)));
} And firebase needs to inject the private void createNotificationChannel() {
// Same as Firebase SDK default channel name and ids
NotificationChannel channel = new NotificationChannel("fcm_fallback_notification_channel", "Miscellaneous", NotificationManager.IMPORTANCE_HIGH);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
private int getNotificationIcon() {
int iconResId;
iconResId = getResources().getIdentifier("ic_notification", "drawable", getPackageName());
if (iconResId == 0) {
iconResId = getApplicationInfo().icon;
}
return iconResId;
}
@Override
public void handleIntent(Intent intent) {
Bundle extras = intent.getExtras();
try {
RemoteMessage message = new RemoteMessage(extras);
RemoteMessage.Notification notificationData = message.getNotification();
if (notificationData == null) {
super.handleIntent(intent);
return;
}
Bundle customExtras = new Bundle();
for (Map.Entry<String, String> entry : message.getData().entrySet()) {
customExtras.putString(entry.getKey(), entry.getValue());
}
createNotificationChannel();
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "fcm_fallback_notification_channel")
.setSmallIcon(getNotificationIcon())
.setContentTitle(notificationData.getTitle())
.setContentText(notificationData.getBody())
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH);
notificationBuilder.getExtras().putBundle("data", customExtras);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Same as tag from Firebase SDK is built
notificationManager.notify("FCM-Notification:" + SystemClock.uptimeMillis(), 0, notificationBuilder.build());
} catch (Exception e) {
super.handleIntent(intent);
}
} |
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
Thank you for your contributions. |
Saw this come through me feed as a close - @aureosouza if you proposed PRs for this (maybe you have but I haven't seen them?) this looks like something we could integrate in react-native-firebase + notifee |
@mikehardy added a PR here #1141, thanks! |
That's fantastic @aureosouza thank you! Please have patience with me on the review (and hopefully merge+release) - got a lot of repos and new arch in rn76 + xcode release / toolchain build issues set me back a bit |
Any luck with the review @mikehardy? |
😆 after quite an odyssey upstream getting react-native 0.76 to work with headlessJS after some regressions with the switch to new architecture quite a bit more process then I remembered (it's been a while...) setting up new firebase projects and apple developer keys and certs and stuff I'm now 🤏 to having notifee be really testable again All the PRs here are queued up on that and about to unspool |
@helenaford based on discussions from here and using similar solution as here. we are trying to fetch the custom
data
on Android overriding thehandleIntent
method fromReactNativeFirebaseMessagingService
(react-native-firebase). As we won't be sending data only notifications to solve this currently, so just like iOS, we want to try to get from same notification:And we are able to see our data correctly when logging in native, when adding extras to intent here
intent.putExtra(entry.getKey(), entry.getValue());
. The problem is that when we call on JS side:Our notifications does not have the data params, we did some investigation on notifee code and noticed when calling
getDisplayedNotifications
on native module we fetch this List:And there is only a strict specific set of variables being sent using
putString
andputBundle
. Is there a way for notifee to pass any extra params from intent back to JS, if they exist?The text was updated successfully, but these errors were encountered: