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

Commit be324e0

Browse files
Sending Data Messages without notification key. #146
1 parent e43c12d commit be324e0

File tree

4 files changed

+12
-20
lines changed

4 files changed

+12
-20
lines changed

platforms/android/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ To make it as easy as possible for consumers of this plugin we bundle those bith
66
Steps to update the `.aar` file:
77

88
* Clone this repo
9-
* Start Android Studio and pick 'import existing project' > `{this repo}/platforms/android/libraryproject`
10-
* Update `firebase/src/main/AndroidManifest.xml` as needed
9+
* Start Android Studio and pick 'import project' > `{this repo}/platforms/android/libraryproject`
10+
* Update `.java` classes and/or `firebase/src/main/AndroidManifest.xml` as needed
1111
* Open the Gradle toolwindow
1212
* Run `firebase > Tasks > build > build`
1313
* The (release) `.aar` will be generated in `firebase/build/outputs/aar`
-198 Bytes
Binary file not shown.

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,41 @@
11
package org.nativescript.plugins.firebase;
22

3-
import android.util.Log;
4-
53
public class FirebasePlugin {
64

7-
static final String TAG = "FirebasePlugin";
8-
95
private static String cachedToken;
106
private static String cachedNotification;
117

128
private static FirebasePluginListener onPushTokenReceivedCallback;
139
private static FirebasePluginListener onNotificationReceivedCallback;
1410

1511
public static void setOnPushTokenReceivedCallback(FirebasePluginListener callbacks) {
16-
Log.d(TAG, "******* Setting onPushTokenReceivedCallback");
1712
onPushTokenReceivedCallback = callbacks;
1813
if (cachedToken != null) {
19-
Log.d(TAG, "******* Setting onPushTokenReceivedCallback - cachedToken is available");
2014
executeOnPushTokenReceivedCallback(cachedToken);
2115
cachedToken = null;
2216
}
2317
}
2418

2519
public static void setOnNotificationReceivedCallback(FirebasePluginListener callbacks) {
26-
Log.d(TAG, "******* Setting onNotificationReceivedCallback");
2720
onNotificationReceivedCallback = callbacks;
2821
if (cachedNotification != null) {
29-
Log.d(TAG, "******* Setting onNotificationReceivedCallback - cachedNotification is available");
3022
executeOnNotificationReceivedCallback(cachedNotification);
3123
cachedNotification = null;
3224
}
3325
}
3426

3527
public static void executeOnPushTokenReceivedCallback(String token) {
3628
if (onPushTokenReceivedCallback != null) {
37-
Log.d(TAG, "******* Sending message to client");
3829
onPushTokenReceivedCallback.success(token);
3930
} else {
40-
Log.d(TAG, "******* No callback function - caching the data for later retrieval.");
4131
cachedToken = token;
4232
}
4333
}
4434

4535
public static void executeOnNotificationReceivedCallback(String notification) {
4636
if (onNotificationReceivedCallback != null) {
47-
Log.d(TAG, "******* Sending message to client");
4837
onNotificationReceivedCallback.success(notification);
4938
} else {
50-
Log.d(TAG, "******* No callback function - caching the data for later retrieval.");
5139
cachedNotification = notification;
5240
}
5341
}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
1515

1616
@Override
1717
public void onMessageReceived(RemoteMessage remoteMessage) {
18-
RemoteMessage.Notification not = remoteMessage.getNotification();
1918
try {
20-
JSONObject json = new JSONObject()
21-
.put("title", not.getTitle())
22-
.put("body", not.getBody())
23-
.put("foreground", true);
19+
final JSONObject json = new JSONObject()
20+
.put("foreground", true)
21+
.put("from", remoteMessage.getFrom());
2422

25-
Map<String, String> data = remoteMessage.getData();
23+
final RemoteMessage.Notification not = remoteMessage.getNotification();
24+
if (not != null) {
25+
json.put("title", not.getTitle())
26+
.put("body", not.getBody());
27+
}
28+
29+
final Map<String, String> data = remoteMessage.getData();
2630
for (Map.Entry<String, String> stringStringEntry : data.entrySet()) {
2731
json.put(stringStringEntry.getKey(), stringStringEntry.getValue());
2832
}

0 commit comments

Comments
 (0)