mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-01-19 13:52:49 +08:00
add jpush.receiveNotificaiton event in platform android
This commit is contained in:
parent
4e2b2d6bb6
commit
cb8f8412b4
@ -55,15 +55,8 @@
|
||||
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){
|
||||
|
@ -171,6 +171,34 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
|
||||
}
|
||||
}
|
||||
static void transmitReceive(String alert, Map<String, Object> 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 {
|
||||
|
@ -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<String,Object> 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<String,Object> 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<String, Object> getNotificationExtras(Intent intent) {
|
||||
Map<String, Object> extrasMap = new HashMap<String, Object>();
|
||||
|
||||
|
@ -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(){
|
||||
|
Loading…
Reference in New Issue
Block a user