Skip to content
This repository was archived by the owner on Feb 7, 2019. It is now read-only.

Commit 6041a16

Browse files
author
Georgi Prodanov
committed
#327565 Fix callback bug and add the Notification object as third argument to the onMessageReceived callback.
1 parent 22d7be6 commit 6041a16

6 files changed

Lines changed: 25 additions & 23 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ In order to use the plugin with Telerik Backend Services take a look at the offi
385385
- the app is in background, the onMessageReceived callback is not invoked
386386
- the app is in background, and the notification in the tray is tapped, the "data" part of the mixed message is available in the extras of the intent of the launched activity - these can be accessed with through nativescript, like they would in Java
387387
- we have removed the default large icon because it forced you to have a large icon and this wasnt the behaviour of FCM notifications
388-
- default color and icon for FCM messages can be set in the AndroidManifest.xml of the project using this XML, inside the <application> tag:
388+
- default color and icon for FCM messages can be set in the AndroidManifest.xml of the project using this XML, inside the "application" tag:
389389

390390
```xml
391391
<meta-data

native-src/android/app/app.iml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@
6565
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
6666
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
6767
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
68-
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
69-
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
70-
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
71-
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
72-
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
73-
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
74-
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
75-
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
7668
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
7769
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
7870
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
@@ -81,6 +73,14 @@
8173
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
8274
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
8375
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
76+
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
78+
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
79+
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
80+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
81+
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
82+
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
83+
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
8484
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
8585
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
8686
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />

native-src/android/app/src/main/java/com/telerik/pushplugin/PushHandlerActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static void processPushBundle(boolean isPushPluginActive, Bundle extras)
6363
}
6464

6565
if (map != null) {
66-
PushPlugin.executeOnMessageReceivedCallback(map);
66+
PushPlugin.executeOnMessageReceivedCallback(map, null);
6767
}
6868
}
6969
}

native-src/android/app/src/main/java/com/telerik/pushplugin/PushPlugin.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ public static void unregister(Context appContext, String projectId, PushPluginLi
6262
*/
6363
public static void setOnMessageReceivedCallback(PushPluginListener callbacks) {
6464
onMessageReceivedCallback = callbacks;
65+
RemoteMessage.Notification whatever = null;
6566

6667
if (cachedData != null) {
67-
executeOnMessageReceivedCallback(cachedData);
68+
executeOnMessageReceivedCallback(cachedData, whatever);
6869
cachedData = null;
6970
}
7071
}
@@ -75,9 +76,9 @@ public static void setOnMessageReceivedCallback(PushPluginListener callbacks) {
7576
*
7677
* @param data
7778
*/
78-
public static void executeOnMessageReceivedCallback(Map<String, String> data) {
79-
JsonObjectExtended json = convertMapToJson(data);
80-
executeOnMessageReceivedCallback(json);
79+
public static void executeOnMessageReceivedCallback(Map<String, String> data, RemoteMessage.Notification notif) {
80+
JsonObjectExtended jsonData = convertMapToJson(data);
81+
executeOnMessageReceivedCallback(jsonData, notif);
8182
}
8283

8384
private static JsonObjectExtended convertMapToJson(Map<String, String> data) {
@@ -96,20 +97,17 @@ private static JsonObjectExtended convertMapToJson(Map<String, String> data) {
9697
return json;
9798
}
9899

99-
private static void executeOnMessageReceivedCallback(JsonObjectExtended dataAsJson) {
100+
private static void executeOnMessageReceivedCallback(JsonObjectExtended dataAsJson, RemoteMessage.Notification notif) {
100101
if (onMessageReceivedCallback != null) {
101-
String msg;
102+
String msg = null;
102103
try {
103104
msg = dataAsJson.getString("message");
104105
} catch (JSONException ex) {
105106
ex.printStackTrace();
106-
return;
107107
}
108108

109-
if (msg != null) {
110-
Log.d(TAG, "Sending message to client: " + msg);
111-
onMessageReceivedCallback.success(msg, dataAsJson.toString());
112-
}
109+
Log.d(TAG, "Sending message to client: " + msg);
110+
onMessageReceivedCallback.success(msg, dataAsJson.toString(), notif);
113111
} else {
114112
Log.d(TAG, "No callback function - caching the data for later retrieval.");
115113
cachedData = dataAsJson;
@@ -122,13 +120,14 @@ private static void executeOnMessageReceivedCallback(JsonObjectExtended dataAsJs
122120
@Override
123121
public void onMessageReceived(RemoteMessage message) {
124122
Map<String, String> data = message.getData();
123+
RemoteMessage.Notification notif = message.getNotification();
125124
Log.d(TAG, "New Push Message: " + data);
126-
Log.d(TAG, "Msg notification: " + message.getNotification());
125+
Log.d(TAG, "Msg notification: " + notif);
127126

128127
// If the application has the callback registered and Plugin is active
129128
// execute the callback. Otherwise, create new notification in the notification bar of the user.
130129
if (onMessageReceivedCallback != null && isActive) {
131-
executeOnMessageReceivedCallback(data);
130+
executeOnMessageReceivedCallback(data, notif);
132131
} else {
133132
Log.d(TAG, "Creating our own notification in tray...");
134133
Context context = getApplicationContext();

native-src/android/app/src/main/java/com/telerik/pushplugin/PushPluginListener.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.telerik.pushplugin;
22

3+
import com.google.firebase.messaging.RemoteMessage;
4+
35
/**
46
* Defines methods for Success and Error callbacks
57
*/
@@ -11,6 +13,7 @@ public interface PushPluginListener {
1113
* @param message
1214
* @param data
1315
*/
16+
void success(Object message, Object data, RemoteMessage.Notification notificationObj);
1417
void success(Object message, Object data);
1518
void success(Object message); // method overload to mimic optional argument
1619

platforms/android/pushplugin.aar

270 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)