From b0b0b687a9a2370f25e46deeb35936ad6109e011 Mon Sep 17 00:00:00 2001 From: Tuan Luong Date: Mon, 14 Oct 2019 21:14:38 +0700 Subject: [PATCH] send data object --- .../RNPushNotificationListenerService.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationListenerService.java b/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationListenerService.java index 40fec92d9..dcd5162a8 100644 --- a/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationListenerService.java +++ b/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationListenerService.java @@ -31,7 +31,6 @@ public class RNPushNotificationListenerService extends FirebaseMessagingService public void onMessageReceived(RemoteMessage message) { String from = message.getFrom(); RemoteMessage.Notification remoteNotification = message.getNotification(); - final Bundle bundle = new Bundle(); // Putting it from remoteNotification first so it can be overriden if message // data has it @@ -39,16 +38,17 @@ public void onMessageReceived(RemoteMessage message) { // ^ It's null when message is from GCM bundle.putString("title", remoteNotification.getTitle()); bundle.putString("message", remoteNotification.getBody()); + bundle.putString("sound", remoteNotification.getSound()); + bundle.putString("color", remoteNotification.getColor()); } - for(Map.Entry entry : message.getData().entrySet()) { - bundle.putString(entry.getKey(), entry.getValue()); - } - JSONObject data = getPushData(bundle.getString("data")); + Map notificationData = message.getData(); + // Copy `twi_body` to `message` to support Twilio - if (bundle.containsKey("twi_body")) { - bundle.putString("message", bundle.getString("twi_body")); + if (notificationData.containsKey("twi_body")) { + bundle.putString("message", notificationData.get("twi_body")); } + JSONObject data = getPushData(notificationData.get("data")); if (data != null) { if (!bundle.containsKey("message")) { @@ -70,6 +70,12 @@ public void onMessageReceived(RemoteMessage message) { } } + Bundle dataBundle = new Bundle(); + for(Map.Entry entry : notificationData.entrySet()) { + dataBundle.putString(entry.getKey(), entry.getValue()); + } + bundle.putParcelable("data", dataBundle); + Log.v(LOG_TAG, "onMessageReceived: " + bundle); // We need to run this on the main thread, as the React code assumes that is true.