-
Notifications
You must be signed in to change notification settings - Fork 261
Description
@helenaford based on discussions from here and using similar solution as here. we are trying to fetch the custom data on Android overriding the handleIntent method from ReactNativeFirebaseMessagingService (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:
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 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:
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 getDisplayedNotifications on native module we fetch this List:
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 putString and putBundle. Is there a way for notifee to pass any extra params from intent back to JS, if they exist?