android推送通知两次

时间:2014-02-10 07:33:53

标签: android notifications push

我正在使用notification.compat构建器来构建通知。在notify方法中,我将id传递为1.控制在广播接收器中只出现一次。但我能够在通知栏中看到两个通知。但是当我在notify方法中将id设为0时,通知只会出现一次。但在这种情况下,在单击通知时,应用程序的主要活动始终打开,即使待处理的意图中提到了其他一些活动。两个通知出现的原因是什么?请帮忙

即使我使用notificationManger.cancelAll(),它也无法正常工作

这是我的代码:

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String title = context.getString(R.string.app_name);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Notification notification = new Notification.Builder(context)
 .setSmallIcon(R.drawable.icon)
 .setContentTitle(ctx.getString(R.string.gcm_notification))
 .setContentText(message)
 .setContentIntent(intent)
 .build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.cancel(0);
notificationManager.cancel(1);
notificationManager.notify(1, notification);

0 个答案:

没有答案