This repository was archived by the owner on Feb 7, 2019. It is now read-only.
File tree Expand file tree Collapse file tree
native-src/android/src/com/telerik/pushplugin Expand file tree Collapse file tree 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+
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" ), data );
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 ;
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