-
Notifications
You must be signed in to change notification settings - Fork 244
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
Android issue: getDisplayedNotifications() does not return custom data fields from FCM push notification #393
Comments
Hi there, currently it is not possible to get the custom data from the fcm message due to the way its created via FCM. It's only possible when the notification is tapped due to the way the intents are created. There's a open git issue and a p/r to try and make the android SDK more flexible where we could alter the notification inside notifee, before its displayed to the end-user. Please give the following links a thumbs up as it'll help show demand for the feature: firebase/firebase-android-sdk#2639 Aside from that, there may be another option of opening up a p/r against firebase-android-sdk to make sure the notification includes custom data when it's built. Or, you could send data-only notifications and create the notifications via notifee. This is quite a common technique that is used, but it's tricky if you already have a production app with a lot of users and migrating over to data-only. |
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. |
@helenaford we are trying to fetch the custom public class ReactNativeFirebaseMessagingService extends FirebaseMessagingService {
...
@Override
public void handleIntent(Intent intent) {
Bundle extras = intent.getExtras();
try {
RemoteMessage message = new RemoteMessage(extras);
RemoteMessage.Notification notificationData = message.getNotification();
// Short-circuit if this is not a display notification
if (notificationData == null) {
super.handleIntent(intent);
return;
}
// 1. Filter the notification as needed using data payload, clickAction, etc.
if (message.getData().containsKey("mydata")) {
// 2. Manually display notifications that match your filter
Map<String, String> data = message.getData();
// Create an intent that will be triggered when the user clicks the notification
for (Map.Entry<String, String> entry : data.entrySet()) {
intent.putExtra(entry.getKey(), entry.getValue());
}
super.handleIntent(intent);
return;
}
} catch (Exception e) {
super.handleIntent(intent);
return;
}
// 3. Fall-through to this for everything else
super.handleIntent(intent);
}
...
} And we are able to log our data correctly, when adding extras to intent here import notifee from '@notifee/react-native';
...
const notifications = await notifee.getDisplayedNotifications(); Our notifications does not have the data params, we did some investigation on notifee code and noticed when calling public static List b() throws Exception {
ArrayList var0;
var0 = new ArrayList.<init>();
if (VERSION.SDK_INT < 23) {
return var0;
} else {
StatusBarNotification[] var1;
int var2 = (var1 = ((NotificationManager)e.a.getSystemService("notification")).getActiveNotifications()).length;
for(int var3 = 0; var3 < var2; ++var3) {
StatusBarNotification var4;
Notification var5;
Bundle var6;
Bundle var10000 = var6 = (var5 = (var4 = var1[var3]).getNotification()).extras;
Bundle var7;
var7 = new Bundle.<init>();
Bundle var8;
var10000 = var8 = var10000.getBundle("notifee.notification");
Bundle var9 = var6.getBundle("notifee.trigger");
if (var10000 == null) {
Bundle var10001 = var8 = new Bundle;
var10001.<init>();
var10001.putString("id", "" + var4.getId());
Object var10;
if ((var10 = var6.get("android.title")) != null) {
var8.putString("title", var10.toString());
}
if ((var10 = var6.get("android.text")) != null) {
var8.putString("body", var10.toString());
}
Object var11;
if ((var11 = var6.get("android.subText")) != null) {
var8.putString("subtitle", var11.toString());
}
var6 = new Bundle.<init>();
if (VERSION.SDK_INT >= 26) {
var6.putString("channelId", var5.getChannelId());
}
var6.putString("tag", var4.getTag());
var6.putString("group", var5.getGroup());
var8.putBundle("android", var6);
var7.putString("id", "" + var4.getId());
} else {
var7.putString("id", "" + var8.get("id"));
}
if (var9 != null) {
var7.putBundle("trigger", var9);
}
var7.putBundle("notification", var8);
var7.putString("date", "" + var4.getPostTime());
var0.add(var7);
}
return var0;
}
} And there is only a strict specific set of variables being sent using |
I have a chat app that receives notifications from FCM push notification. If 3 users send messages to me, I will have 3 push notifications. What I want to when I open a conversation is to get all the notifications I received with the
getDisplayedNotifications()
function and filter them based on FCM push notification's custom data field called event (id of the conversation). I can access that field from PNs custom data in IOS at this path:notification.data.event
on the iOS device, but on the Android I can't.data
field is missing from theNotification
objectThis is what
getDisplayedNotifications
returns on IOS:and this is what
getDisplayedNotifications
returns on Android:ignore the length of the array.
Do you have any solutions to this issue? (the display is handled by default, not Notifee)
The text was updated successfully, but these errors were encountered: