Skip to content

Commit 7cb3e22

Browse files
committed
Merge pull request #100 from darkterrorooo/master
fix #99 android jpush.openNotification 事件调用两次
2 parents 0af2f60 + a3ad96f commit 7cb3e22

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

example/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@
5454
}
5555
var onReceiveNotification = function(event){
5656
try{
57-
var alert
57+
var alertContent
5858
if(device.platform == "Android"){
59-
alert = window.plugins.jPushPlugin.receiveNotification.alert;
59+
alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
6060
}else{
61-
alert = event.aps.alert;
61+
alertContent = event.aps.alert;
6262
}
63-
$("#notificationResult").html(alert);
63+
$("#notificationResult").html(alertContent);
6464

6565
}
6666
catch(exeption){

src/android/JPushPlugin.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import cn.jpush.android.api.JPushInterface;
2727
import cn.jpush.android.data.JPushLocalNotification;
2828
import cn.jpush.android.api.TagAliasCallback;
29+
import android.util.Log;
30+
2931

3032
public class JPushPlugin extends CordovaPlugin {
3133
private final static List<String> methodList =
@@ -56,7 +58,9 @@ public class JPushPlugin extends CordovaPlugin {
5658

5759
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
5860
private static JPushPlugin instance;
61+
private static String TAG = "Client JPushPlugin";
5962

63+
public static boolean bOpenNotificationAlert = true;
6064
public static String notificationAlert;
6165
public static Map<String, Object> notificationExtras=new HashMap<String, Object>();
6266
public static String openNotificationAlert;
@@ -73,12 +77,19 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
7377

7478
//JPushPlugin.notificationAlert = alert;
7579
//JPushPlugin.notificationExtras = extras;
76-
if(JPushPlugin.openNotificationAlert != null){
77-
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert, JPushPlugin.openNotificationExtras);
78-
}
79-
if(JPushPlugin.notificationAlert!=null){
80-
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert, JPushPlugin.notificationExtras);
81-
}
80+
81+
if(JPushPlugin.bOpenNotificationAlert){
82+
83+
JPushPlugin.bOpenNotificationAlert = false;
84+
if(JPushPlugin.openNotificationAlert != null){
85+
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert, JPushPlugin.openNotificationExtras);
86+
}
87+
if(JPushPlugin.notificationAlert!=null){
88+
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert, JPushPlugin.notificationExtras);
89+
}
90+
91+
}
92+
8293

8394
//JPushInterface.init(cordova.getActivity().getApplicationContext());
8495
}
@@ -226,7 +237,7 @@ public void run() {
226237
JSONArray.class, CallbackContext.class);
227238
method.invoke(JPushPlugin.this, data, callbackContext);
228239
} catch (Exception e) {
229-
System.out.println(e.toString());
240+
Log.e(TAG,e.toString());
230241
}
231242
}
232243
});

src/android/MyReceiver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private void handlingNotificationOpen(Context context,Intent intent){
4848
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
4949
launch.addCategory(Intent.CATEGORY_LAUNCHER);
5050
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
51-
51+
JPushPlugin.bOpenNotificationAlert = true;
5252
JPushPlugin.openNotificationAlert = alert;
5353
JPushPlugin.openNotificationExtras = extras;
5454

0 commit comments

Comments
 (0)