Search in sources :

Example 1 with Notification

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);
}
Also used : Context(android.content.Context) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) IntentFilter(android.content.IntentFilter) RemoteMessage(com.google.firebase.messaging.RemoteMessage) WritableMap(com.facebook.react.bridge.WritableMap) Set(java.util.Set) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) Map(java.util.Map) ReadableMap(com.facebook.react.bridge.ReadableMap) WritableMap(com.facebook.react.bridge.WritableMap) Notification(com.google.firebase.messaging.RemoteMessage.Notification)

Aggregations

BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 ReactApplicationContext (com.facebook.react.bridge.ReactApplicationContext)1 ReadableMap (com.facebook.react.bridge.ReadableMap)1 WritableMap (com.facebook.react.bridge.WritableMap)1 RemoteMessage (com.google.firebase.messaging.RemoteMessage)1 Notification (com.google.firebase.messaging.RemoteMessage.Notification)1 Map (java.util.Map)1 Set (java.util.Set)1