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

Commit a0664fa

Browse files
committed
Merge pull request #11 from fritzvd/fritzvd/extra-parameters-for-callback
Fritzvd/extra parameters for callback
2 parents 9bc640a + 2fd96ff commit a0664fa

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import android.os.Bundle;
55
import android.util.Log;
66
import com.google.android.gms.gcm.GcmListenerService;
7+
import org.json.JSONException;
8+
import org.json.JSONObject;
9+
10+
import java.util.Set;
711

812
/**
913
* Push plugin extends the GCM Listener Service and has to be registered in the AndroidManifest
@@ -79,7 +83,18 @@ public static void setOnMessageReceivedCallback(PushPluginListener callbacks) {
7983
public static void executeOnMessageReceivedCallback(Bundle data) {
8084
if (onMessageReceivedCallback != null) {
8185
Log.d(TAG, "Sending message to client: " + data.getString("message"));
82-
onMessageReceivedCallback.success(data.getString("message"));
86+
JSONObject dataAsJson = new JSONObject();
87+
Set<String> keys = data.keySet();
88+
for (String key : keys) {
89+
try {
90+
// json.put(key, bundle.get(key)); see edit below
91+
dataAsJson.put(key, JSONObject.wrap(data.get(key)));
92+
} catch(JSONException e) {
93+
// Log.d(TAG, "Error thrown: ", e.toStringu());
94+
//Handle exception here
95+
}
96+
}
97+
onMessageReceivedCallback.success(data.getString("message"), dataAsJson.toString());
8398
} else {
8499
Log.d(TAG, "No callback function - caching the data for later retrieval.");
85100
cachedData = data;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ public interface PushPluginListener {
88
* Defines a success callback method, which is used to pass success function reference
99
* from the nativescript to the Java plugin
1010
*
11+
* @param message
1112
* @param data
1213
*/
13-
void success(Object data);
14+
void success(Object message, Object data);
15+
void success(Object message); // method overload to mimic optional argument
1416

1517

1618
/**

0 commit comments

Comments
 (0)