Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

[Android] send data object along with notification #1212

Merged
merged 1 commit into from
Apr 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ 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
if (remoteNotification != null) {
// ^ 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<String, String> entry : message.getData().entrySet()) {
bundle.putString(entry.getKey(), entry.getValue());
}
JSONObject data = getPushData(bundle.getString("data"));
Map<String, String> 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")) {
Expand All @@ -70,6 +70,12 @@ public void onMessageReceived(RemoteMessage message) {
}
}

Bundle dataBundle = new Bundle();
for(Map.Entry<String, String> 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.
Expand Down