Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 5645bbe

Browse files
author
Blake Peterman
committed
Put the data into the data key for Android
Before this change the elements in the data object are put into the main json object. The docs say that this should be underneath the data key. This causes an issue with TypeScript because you're not able to access keys not defined in the interface.
1 parent ea4b26e commit 5645bbe

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed
38 Bytes
Binary file not shown.

platforms/android/libraryproject/firebase/src/main/java/org/nativescript/plugins/firebase/MyFirebaseMessagingService.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
1717
public void onMessageReceived(RemoteMessage remoteMessage) {
1818
try {
1919
final JSONObject json = new JSONObject()
20-
.put("foreground", true)
21-
.put("from", remoteMessage.getFrom());
20+
.put("foreground", true)
21+
.put("from", remoteMessage.getFrom());
2222

2323
final RemoteMessage.Notification not = remoteMessage.getNotification();
2424
if (not != null) {
2525
json.put("title", not.getTitle())
26-
.put("body", not.getBody());
26+
.put("body", not.getBody());
2727
}
2828

2929
final Map<String, String> data = remoteMessage.getData();
30+
final JSONObject data_json = new JSONObject();
3031
for (Map.Entry<String, String> stringStringEntry : data.entrySet()) {
31-
json.put(stringStringEntry.getKey(), stringStringEntry.getValue());
32+
data_json.put(stringStringEntry.getKey(), stringStringEntry.getValue());
3233
}
34+
json.put("data", data_json);
3335

3436
FirebasePlugin.executeOnNotificationReceivedCallback(json.toString());
3537
} catch (JSONException e) {
@@ -62,4 +64,4 @@ private void sendNotification(String messageBody) {
6264
}
6365
*/
6466

65-
}
67+
}

0 commit comments

Comments
 (0)