Closed aureosouza closed 4 weeks ago
FYI we had to implement a patch for this, we've added an extra fetchNotificationData
to getDisplayedNotifications
module method, that injects the data param from firebase (if it exists):
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 data
param as well, for this we added a handleIntent override for the class that extends FirebaseMessagingService
(in our case we use react-native-firebase, so that would be ReactNativeFirebaseMessagingService):
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?
This issue will be closed in 15 days if no further activity occurs.
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
@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?