mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-03-03 21:32:51 +08:00
fix push notificaiton and add open notificaiotn evet
This commit is contained in:
parent
34857a1eea
commit
7cc3239e1b
@ -74,6 +74,17 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
return data;
|
||||
}
|
||||
|
||||
private static JSONObject openNotificationObject(String alert,
|
||||
Map<String, String> extras){
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
data.put("alert", alert);
|
||||
data.put("extras", new JSONObject(extras));
|
||||
} catch (JSONException e) {
|
||||
|
||||
}
|
||||
return data;
|
||||
}
|
||||
static void transmitPush(String message, Map<String, String> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
@ -90,7 +101,22 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
|
||||
}
|
||||
}
|
||||
static void transmitOpen(String alert, Map<String, String> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
JSONObject data = openNotificationObject(alert, extras);
|
||||
String js = String
|
||||
.format("window.plugins.jPushPlugin.openNotificationCallback(%s);",
|
||||
data.toString());
|
||||
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 {
|
||||
@ -348,10 +374,10 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
.format("cordova.fireDocumentEvent('jpush.setTagsWithAlias',%s)",
|
||||
data.toString());
|
||||
instance.webView.sendJavascript(jsEvent);
|
||||
String js = String
|
||||
.format("window.plugins.jPushPlugin.pushCallback('%s');",
|
||||
data.toString());
|
||||
instance.webView.sendJavascript(js);
|
||||
// String js = String
|
||||
// .format("window.plugins.jPushPlugin.pushCallback('%s');",
|
||||
// data.toString());
|
||||
// instance.webView.sendJavascript(js);
|
||||
|
||||
|
||||
} catch (JSONException e) {
|
||||
|
@ -50,6 +50,8 @@ public class MyReceiver extends BroadcastReceiver {
|
||||
JPushPlugin.notificationAlert = alert;
|
||||
JPushPlugin.notificationExtras = extras;
|
||||
|
||||
JPushPlugin.transmitOpen(alert, extras);
|
||||
|
||||
context.startActivity(launch);
|
||||
}
|
||||
private Map<String, String> getNotificationExtras(Intent intent) {
|
||||
|
@ -80,10 +80,22 @@ JPushPlugin.prototype.pushCallback = function(data){
|
||||
try{
|
||||
console.log(data);
|
||||
var bToObj=JSON.parse(data);
|
||||
var code = bToObj.resultCode;
|
||||
var tags = bToObj.resultTags;
|
||||
var alias = bToObj.resultAlias;
|
||||
console.log("JPushPlugin:callBack--code is "+code+" tags is "+tags + " alias is "+alias);
|
||||
var message = bToObj.message;
|
||||
var extras = bToObj.extras;
|
||||
console.log("JPushPlugin:pushCallback--message is "+message+" extras is "+extras );
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
//
|
||||
JPushPlugin.prototype.openNotificationCallback = function(data){
|
||||
try{
|
||||
console.log(data);
|
||||
var bToObj = JSON.parse(data);
|
||||
var alert = bToObj.alert;
|
||||
var extras = bToObj.extras;
|
||||
console.log("JPushPlugin:openNotificationCallback--alert is "+code+" extras is "+extras);
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
|
Loading…
Reference in New Issue
Block a user