This repository was archived by the owner on Feb 7, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 8 files changed +21
-5
lines changed
src/com/telerik/pushplugin Expand file tree Collapse file tree 8 files changed +21
-5
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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" >
Original file line number Diff line number Diff line change 1212
1313android.library =true
1414# Project target.
15- target =android-21
15+ target =android-23
Original file line number Diff line number Diff line change 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" />
Original file line number Diff line number Diff line change 44import android .os .Bundle ;
55import android .util .Log ;
66import 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 ;
Original file line number Diff line number Diff 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 /**
You can’t perform that action at this time.
0 commit comments