diff --git a/example/index.html b/example/index.html
index 1e472fd..36fdd33 100644
--- a/example/index.html
+++ b/example/index.html
@@ -54,16 +54,9 @@
}
var onReceiveNotification = function(event){
try{
-
- var eventContent="{";
- for(var key in event){
- if(key=="type"){
- break
- }
- eventContent+=key+":"+JSON.stringify(event[key])+"\n"
- }
- eventContent+="}";
- $("#notificationResult").html(eventContent);
+
+ var alert = window.plugins.jPushPlugin.receiveNotification.alert;
+ $("#notificationResult").html(alert);
}
catch(exeption){
diff --git a/src/android/JPushPlugin.java b/src/android/JPushPlugin.java
index 8673a58..462bb6f 100644
--- a/src/android/JPushPlugin.java
+++ b/src/android/JPushPlugin.java
@@ -171,6 +171,34 @@ public class JPushPlugin extends CordovaPlugin {
}
}
+ static void transmitReceive(String alert, Map extras) {
+ if (instance == null) {
+ return;
+ }
+ JSONObject data = openNotificationObject(alert, extras);
+ String js = String
+ .format("window.plugins.jPushPlugin.receiveNotificationInAndroidCallback('%s');",
+ data.toString());
+// {"alert":"ding",
+// "extras":{
+// "cn.jpush.android.MSG_ID":"1691785879",
+// "app":"com.thi.pushtest",
+// "cn.jpush.android.ALERT":"ding",
+// "cn.jpush.android.EXTRA":{},
+// "cn.jpush.android.PUSH_ID":"1691785879",
+// "cn.jpush.android.NOTIFICATION_ID":1691785879,
+// "cn.jpush.android.NOTIFICATION_TYPE":"0"}}
+ try {
+
+ instance.webView.sendJavascript(js);
+
+ } catch (NullPointerException e) {
+
+ } catch (Exception e) {
+
+ }
+ }
+
@Override
public boolean execute(final String action, final JSONArray data,
final CallbackContext callbackContext) throws JSONException {
diff --git a/src/android/MyReceiver.java b/src/android/MyReceiver.java
index db07e69..ccd0749 100644
--- a/src/android/MyReceiver.java
+++ b/src/android/MyReceiver.java
@@ -23,6 +23,7 @@ public class MyReceiver extends BroadcastReceiver {
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
handlingReceivedMessage(intent);
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
+ handlingNotificationReceive(context,intent);
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
handlingNotificationOpen(context,intent);
@@ -37,6 +38,7 @@ public class MyReceiver extends BroadcastReceiver {
String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
Map extras = getNotificationExtras(intent);
+
JPushPlugin.transmitPush(msg, extras);
}
private void handlingNotificationOpen(Context context,Intent intent){
@@ -54,6 +56,19 @@ public class MyReceiver extends BroadcastReceiver {
context.startActivity(launch);
}
+ private void handlingNotificationReceive(Context context,Intent intent){
+ String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
+ Map extras = getNotificationExtras(intent);
+
+ Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
+ launch.addCategory(Intent.CATEGORY_LAUNCHER);
+ launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
+
+ JPushPlugin.notificationAlert = alert;
+ JPushPlugin.notificationExtras = extras;
+
+ JPushPlugin.transmitReceive(alert, extras);
+ }
private Map getNotificationExtras(Intent intent) {
Map extrasMap = new HashMap();
diff --git a/www/JPushPlugin.js b/www/JPushPlugin.js
index 8867bab..5c76432 100644
--- a/www/JPushPlugin.js
+++ b/www/JPushPlugin.js
@@ -6,6 +6,7 @@ var JPushPlugin = function(){
JPushPlugin.prototype.receiveMessage={}
JPushPlugin.prototype.openNotification={}
+JPushPlugin.prototype.receiveNotification={}
JPushPlugin.prototype.isPlatformIOS = function(){
@@ -188,6 +189,31 @@ JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
console.log(exception);
}
}
+JPushPlugin.prototype.receiveNotificationInAndroidCallback = function(data){
+ try{
+ console.log("JPushPlugin:receiveNotificationInAndroidCallback");
+ var bToObj = JSON.parse(data);
+ this.receiveNotification=bToObj;
+ cordova.fireDocumentEvent('jpush.receiveNotification',null);
+
+ //console.log(data);
+ //var bToObj = JSON.parse(data);
+ //var alert = bToObj.alert;
+ //var extras = bToObj.extras;
+ //console.log(alert);
+
+ //console.log(extras['cn.jpush.android.MSG_ID']);
+ //console.log(extras['app']);
+ //console.log(extras['cn.jpush.android.NOTIFICATION_CONTENT_TITLE']);
+ //console.log(extras['cn.jpush.android.EXTRA']);
+ //console.log(extras['cn.jpush.android.PUSH_ID']);
+ //console.log(extras['cn.jpush.android.NOTIFICATION_ID']);
+ //console.log("JPushPlugin:openNotificationCallback is ready");
+ }
+ catch(exception){
+ console.log(exception);
+ }
+}
//android single
JPushPlugin.prototype.setBasicPushNotificationBuilder = function(){