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

Commit

Permalink
Merge pull request #12 from NativeScript/pzlatanov/android-full-objec…
Browse files Browse the repository at this point in the history
…t-to-callback

Pzlatanov/android full object to callback
  • Loading branch information
r0bot committed Jan 21, 2016
2 parents 9bc640a + abd0cae commit 96d7ef3
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ The code for the Push Plugin for NativeScript.
var settings = {
// Android settings
senderID: '<ENTER_YOUR_PROJECT_NUMBER>', // 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));
},

Expand Down
1 change: 1 addition & 0 deletions native-src/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package="com.example.pushplugin"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23"/>
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name="ACTIVITY_ENTRY_NAME"
android:label="@string/app_name">
Expand Down
Binary file removed native-src/android/libs/google-play-services.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion native-src/android/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

android.library=true
# Project target.
target=android-21
target=android-23
2 changes: 1 addition & 1 deletion native-src/android/pushplugin.iml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform - 1.7" jdkType="Android SDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="google-play-services" level="project" />
<orderEntry type="library" name="android-support-v4" level="project" />
Expand Down
15 changes: 14 additions & 1 deletion native-src/android/src/com/telerik/pushplugin/PushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


/**
Expand Down
Binary file modified platforms/android/libs/pushplugin.jar
Binary file not shown.

0 comments on commit 96d7ef3

Please sign in to comment.