Merge pull request #100 from darkterrorooo/master

fix #99 android jpush.openNotification 事件调用两次
This commit is contained in:
darkterrorooo 2015-12-09 18:42:35 +08:00
commit 7cb3e22e14
3 changed files with 23 additions and 12 deletions

View File

@ -54,13 +54,13 @@
} }
var onReceiveNotification = function(event){ var onReceiveNotification = function(event){
try{ try{
var alert var alertContent
if(device.platform == "Android"){ if(device.platform == "Android"){
alert = window.plugins.jPushPlugin.receiveNotification.alert; alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
}else{ }else{
alert = event.aps.alert; alertContent = event.aps.alert;
} }
$("#notificationResult").html(alert); $("#notificationResult").html(alertContent);
} }
catch(exeption){ catch(exeption){

View File

@ -26,6 +26,8 @@ import cn.jpush.android.api.CustomPushNotificationBuilder;
import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.data.JPushLocalNotification; import cn.jpush.android.data.JPushLocalNotification;
import cn.jpush.android.api.TagAliasCallback; import cn.jpush.android.api.TagAliasCallback;
import android.util.Log;
public class JPushPlugin extends CordovaPlugin { public class JPushPlugin extends CordovaPlugin {
private final static List<String> methodList = private final static List<String> methodList =
@ -56,7 +58,9 @@ public class JPushPlugin extends CordovaPlugin {
private ExecutorService threadPool = Executors.newFixedThreadPool(1); private ExecutorService threadPool = Executors.newFixedThreadPool(1);
private static JPushPlugin instance; private static JPushPlugin instance;
private static String TAG = "Client JPushPlugin";
public static boolean bOpenNotificationAlert = true;
public static String notificationAlert; public static String notificationAlert;
public static Map<String, Object> notificationExtras=new HashMap<String, Object>(); public static Map<String, Object> notificationExtras=new HashMap<String, Object>();
public static String openNotificationAlert; public static String openNotificationAlert;
@ -73,12 +77,19 @@ public class JPushPlugin extends CordovaPlugin {
//JPushPlugin.notificationAlert = alert; //JPushPlugin.notificationAlert = alert;
//JPushPlugin.notificationExtras = extras; //JPushPlugin.notificationExtras = extras;
if(JPushPlugin.openNotificationAlert != null){
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert, JPushPlugin.openNotificationExtras); if(JPushPlugin.bOpenNotificationAlert){
}
if(JPushPlugin.notificationAlert!=null){ JPushPlugin.bOpenNotificationAlert = false;
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert, JPushPlugin.notificationExtras); if(JPushPlugin.openNotificationAlert != null){
} JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert, JPushPlugin.openNotificationExtras);
}
if(JPushPlugin.notificationAlert!=null){
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert, JPushPlugin.notificationExtras);
}
}
//JPushInterface.init(cordova.getActivity().getApplicationContext()); //JPushInterface.init(cordova.getActivity().getApplicationContext());
} }
@ -226,7 +237,7 @@ public class JPushPlugin extends CordovaPlugin {
JSONArray.class, CallbackContext.class); JSONArray.class, CallbackContext.class);
method.invoke(JPushPlugin.this, data, callbackContext); method.invoke(JPushPlugin.this, data, callbackContext);
} catch (Exception e) { } catch (Exception e) {
System.out.println(e.toString()); Log.e(TAG,e.toString());
} }
} }
}); });

View File

@ -48,7 +48,7 @@ public class MyReceiver extends BroadcastReceiver {
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
launch.addCategory(Intent.CATEGORY_LAUNCHER); launch.addCategory(Intent.CATEGORY_LAUNCHER);
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP); launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
JPushPlugin.bOpenNotificationAlert = true;
JPushPlugin.openNotificationAlert = alert; JPushPlugin.openNotificationAlert = alert;
JPushPlugin.openNotificationExtras = extras; JPushPlugin.openNotificationExtras = extras;