diff --git a/README.md b/README.md index aa90462..b2a124d 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ The code for the Push Plugin for NativeScript. var settings = { // Android settings senderID: '', // Android: Required setting with the sender/project number - notificationCallbackAndroid: function(message) { // Android: Callback to invoke when a new push is received. + notificationCallbackAndroid: function(message, pushNotificationObject) { // Android: Callback to invoke when a new push is received. alert(JSON.stringify(message)); }, diff --git a/native-src/android/AndroidManifest.xml b/native-src/android/AndroidManifest.xml index a3a4e0a..de0735c 100644 --- a/native-src/android/AndroidManifest.xml +++ b/native-src/android/AndroidManifest.xml @@ -3,6 +3,7 @@ package="com.example.pushplugin" android:versionCode="1" android:versionName="1.0"> + diff --git a/native-src/android/libs/google-play-services.jar b/native-src/android/libs/google-play-services.jar deleted file mode 100644 index b9798f0..0000000 Binary files a/native-src/android/libs/google-play-services.jar and /dev/null differ diff --git a/native-src/android/project.properties b/native-src/android/project.properties index 5916622..b3ce2be 100644 --- a/native-src/android/project.properties +++ b/native-src/android/project.properties @@ -12,4 +12,4 @@ android.library=true # Project target. -target=android-21 +target=android-23 diff --git a/native-src/android/pushplugin.iml b/native-src/android/pushplugin.iml index 22a6bc6..3b0999d 100644 --- a/native-src/android/pushplugin.iml +++ b/native-src/android/pushplugin.iml @@ -14,7 +14,7 @@ - + diff --git a/native-src/android/src/com/telerik/pushplugin/PushPlugin.java b/native-src/android/src/com/telerik/pushplugin/PushPlugin.java index e74c976..538cb18 100644 --- a/native-src/android/src/com/telerik/pushplugin/PushPlugin.java +++ b/native-src/android/src/com/telerik/pushplugin/PushPlugin.java @@ -4,6 +4,9 @@ import android.os.Bundle; import android.util.Log; import com.google.android.gms.gcm.GcmListenerService; +import org.json.JSONException; +import org.json.JSONObject; +import java.util.Set; /** * Push plugin extends the GCM Listener Service and has to be registered in the AndroidManifest @@ -79,7 +82,17 @@ public static void setOnMessageReceivedCallback(PushPluginListener callbacks) { public static void executeOnMessageReceivedCallback(Bundle data) { if (onMessageReceivedCallback != null) { Log.d(TAG, "Sending message to client: " + data.getString("message")); - onMessageReceivedCallback.success(data.getString("message")); + JSONObject dataAsJson = new JSONObject(); + Set keys = data.keySet(); + for (String key : keys) { + try { + dataAsJson.put(key, JSONObject.wrap(data.get(key))); + } catch(JSONException e) { + Log.d(TAG, "Error thrown while parsing push notification data bundle to json: " + e.getMessage()); + //Handle exception here + } + } + onMessageReceivedCallback.success(data.getString("message"), dataAsJson.toString()); } else { Log.d(TAG, "No callback function - caching the data for later retrieval."); cachedData = data; diff --git a/native-src/android/src/com/telerik/pushplugin/PushPluginListener.java b/native-src/android/src/com/telerik/pushplugin/PushPluginListener.java index dc5e604..a00bc6c 100644 --- a/native-src/android/src/com/telerik/pushplugin/PushPluginListener.java +++ b/native-src/android/src/com/telerik/pushplugin/PushPluginListener.java @@ -8,9 +8,11 @@ public interface PushPluginListener { * Defines a success callback method, which is used to pass success function reference * from the nativescript to the Java plugin * + * @param message * @param data */ - void success(Object data); + void success(Object message, Object data); + void success(Object message); // method overload to mimic optional argument /** diff --git a/platforms/android/libs/pushplugin.jar b/platforms/android/libs/pushplugin.jar index f5c1f26..beaeee5 100644 Binary files a/platforms/android/libs/pushplugin.jar and b/platforms/android/libs/pushplugin.jar differ