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

Commit 96d7ef3

Browse files
committed
Merge pull request #12 from NativeScript/pzlatanov/android-full-object-to-callback
Pzlatanov/android full object to callback
2 parents 9bc640a + abd0cae commit 96d7ef3

File tree

8 files changed

+21
-5
lines changed

8 files changed

+21
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ The code for the Push Plugin for NativeScript.
124124
var settings = {
125125
// Android settings
126126
senderID: '<ENTER_YOUR_PROJECT_NUMBER>', // Android: Required setting with the sender/project number
127-
notificationCallbackAndroid: function(message) { // Android: Callback to invoke when a new push is received.
127+
notificationCallbackAndroid: function(message, pushNotificationObject) { // Android: Callback to invoke when a new push is received.
128128
alert(JSON.stringify(message));
129129
},
130130

native-src/android/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package="com.example.pushplugin"
44
android:versionCode="1"
55
android:versionName="1.0">
6+
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23"/>
67
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
78
<activity android:name="ACTIVITY_ENTRY_NAME"
89
android:label="@string/app_name">
-4.85 MB
Binary file not shown.

native-src/android/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212

1313
android.library=true
1414
# Project target.
15-
target=android-21
15+
target=android-23

native-src/android/pushplugin.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
1515
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
1616
</content>
17-
<orderEntry type="jdk" jdkName="Android API 21 Platform - 1.7" jdkType="Android SDK" />
17+
<orderEntry type="inheritedJdk" />
1818
<orderEntry type="sourceFolder" forTests="false" />
1919
<orderEntry type="library" name="google-play-services" level="project" />
2020
<orderEntry type="library" name="android-support-v4" level="project" />

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
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+
import java.util.Set;
710

811
/**
912
* 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) {
7982
public static void executeOnMessageReceivedCallback(Bundle data) {
8083
if (onMessageReceivedCallback != null) {
8184
Log.d(TAG, "Sending message to client: " + data.getString("message"));
82-
onMessageReceivedCallback.success(data.getString("message"));
85+
JSONObject dataAsJson = new JSONObject();
86+
Set<String> keys = data.keySet();
87+
for (String key : keys) {
88+
try {
89+
dataAsJson.put(key, JSONObject.wrap(data.get(key)));
90+
} catch(JSONException e) {
91+
Log.d(TAG, "Error thrown while parsing push notification data bundle to json: " + e.getMessage());
92+
//Handle exception here
93+
}
94+
}
95+
onMessageReceivedCallback.success(data.getString("message"), dataAsJson.toString());
8396
} else {
8497
Log.d(TAG, "No callback function - caching the data for later retrieval.");
8598
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
/**

platforms/android/libs/pushplugin.jar

891 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)