Skip to content

Commit b0b0b68

Browse files
committed
send data object
1 parent b4ea8fb commit b0b0b68

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationListenerService.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,24 @@ public class RNPushNotificationListenerService extends FirebaseMessagingService
3131
public void onMessageReceived(RemoteMessage message) {
3232
String from = message.getFrom();
3333
RemoteMessage.Notification remoteNotification = message.getNotification();
34-
3534
final Bundle bundle = new Bundle();
3635
// Putting it from remoteNotification first so it can be overriden if message
3736
// data has it
3837
if (remoteNotification != null) {
3938
// ^ It's null when message is from GCM
4039
bundle.putString("title", remoteNotification.getTitle());
4140
bundle.putString("message", remoteNotification.getBody());
41+
bundle.putString("sound", remoteNotification.getSound());
42+
bundle.putString("color", remoteNotification.getColor());
4243
}
4344

44-
for(Map.Entry<String, String> entry : message.getData().entrySet()) {
45-
bundle.putString(entry.getKey(), entry.getValue());
46-
}
47-
JSONObject data = getPushData(bundle.getString("data"));
45+
Map<String, String> notificationData = message.getData();
46+
4847
// Copy `twi_body` to `message` to support Twilio
49-
if (bundle.containsKey("twi_body")) {
50-
bundle.putString("message", bundle.getString("twi_body"));
48+
if (notificationData.containsKey("twi_body")) {
49+
bundle.putString("message", notificationData.get("twi_body"));
5150
}
51+
JSONObject data = getPushData(notificationData.get("data"));
5252

5353
if (data != null) {
5454
if (!bundle.containsKey("message")) {
@@ -70,6 +70,12 @@ public void onMessageReceived(RemoteMessage message) {
7070
}
7171
}
7272

73+
Bundle dataBundle = new Bundle();
74+
for(Map.Entry<String, String> entry : notificationData.entrySet()) {
75+
dataBundle.putString(entry.getKey(), entry.getValue());
76+
}
77+
bundle.putParcelable("data", dataBundle);
78+
7379
Log.v(LOG_TAG, "onMessageReceived: " + bundle);
7480

7581
// We need to run this on the main thread, as the React code assumes that is true.

0 commit comments

Comments
 (0)