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.
124
124
var settings = {
125
125
// Android settings
126
126
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.
128
128
alert (JSON .stringify (message));
129
129
},
130
130
Original file line number Diff line number Diff line change 3
3
package =" com.example.pushplugin"
4
4
android : versionCode =" 1"
5
5
android : versionName =" 1.0" >
6
+ <uses-sdk android : minSdkVersion =" 19" android : targetSdkVersion =" 23" />
6
7
<application android : label =" @string/app_name" android : icon =" @drawable/ic_launcher" >
7
8
<activity android : name =" ACTIVITY_ENTRY_NAME"
8
9
android : label =" @string/app_name" >
Original file line number Diff line number Diff line change 12
12
13
13
android.library =true
14
14
# Project target.
15
- target =android-21
15
+ target =android-23
Original file line number Diff line number Diff line change 14
14
<sourceFolder url =" file://$MODULE_DIR$/src" isTestSource =" false" />
15
15
<sourceFolder url =" file://$MODULE_DIR$/gen" isTestSource =" false" generated =" true" />
16
16
</content >
17
- <orderEntry type =" jdk " jdkName = " Android API 21 Platform - 1.7 " jdkType = " Android SDK " />
17
+ <orderEntry type =" inheritedJdk " />
18
18
<orderEntry type =" sourceFolder" forTests =" false" />
19
19
<orderEntry type =" library" name =" google-play-services" level =" project" />
20
20
<orderEntry type =" library" name =" android-support-v4" level =" project" />
Original file line number Diff line number Diff line change 4
4
import android .os .Bundle ;
5
5
import android .util .Log ;
6
6
import com .google .android .gms .gcm .GcmListenerService ;
7
+ import org .json .JSONException ;
8
+ import org .json .JSONObject ;
9
+ import java .util .Set ;
7
10
8
11
/**
9
12
* 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) {
79
82
public static void executeOnMessageReceivedCallback (Bundle data ) {
80
83
if (onMessageReceivedCallback != null ) {
81
84
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 ());
83
96
} else {
84
97
Log .d (TAG , "No callback function - caching the data for later retrieval." );
85
98
cachedData = data ;
Original file line number Diff line number Diff line change @@ -8,9 +8,11 @@ public interface PushPluginListener {
8
8
* Defines a success callback method, which is used to pass success function reference
9
9
* from the nativescript to the Java plugin
10
10
*
11
+ * @param message
11
12
* @param data
12
13
*/
13
- void success (Object data );
14
+ void success (Object message , Object data );
15
+ void success (Object message ); // method overload to mimic optional argument
14
16
15
17
16
18
/**
You can’t perform that action at this time.
0 commit comments