use of com.google.firebase.messaging.RemoteMessage.Notification in project react-native-fcm by evollu.
the class FIRMessagingModule method registerMessageHandler.
private void registerMessageHandler() {
IntentFilter intentFilter = new IntentFilter("com.evollu.react.fcm.ReceiveNotification");
LocalBroadcastManager.getInstance(getReactApplicationContext()).registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (getReactApplicationContext().hasActiveCatalystInstance()) {
RemoteMessage message = intent.getParcelableExtra("data");
WritableMap params = Arguments.createMap();
WritableMap fcmData = Arguments.createMap();
if (message.getNotification() != null) {
Notification notification = message.getNotification();
fcmData.putString("title", notification.getTitle());
fcmData.putString("body", notification.getBody());
fcmData.putString("color", notification.getColor());
fcmData.putString("icon", notification.getIcon());
fcmData.putString("tag", notification.getTag());
fcmData.putString("action", notification.getClickAction());
}
params.putMap("fcm", fcmData);
params.putString("collapse_key", message.getCollapseKey());
params.putString("from", message.getFrom());
params.putString("google.message_id", message.getMessageId());
params.putDouble("google.sent_time", message.getSentTime());
if (message.getData() != null) {
Map<String, String> data = message.getData();
Set<String> keysIterator = data.keySet();
for (String key : keysIterator) {
params.putString(key, data.get(key));
}
}
sendEvent("FCMNotificationReceived", params);
}
}
}, intentFilter);
}
Aggregations