每次我发送通知时,设备都会像通知已发送无数次一样。也就是说,铃声和振动会一直响起,直到我打开通知菜单。如果我注释掉 notification.flag |= 行,我可以停止这种行为,但是我无法使用自动取消标志。关于造成这种情况的任何想法?
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(resourceID)
.setContentTitle(title)
.setContentText(contentText)
.setSound(soundUri, RingtoneManager.TYPE_NOTIFICATION)
.setVibrate(CommonUtilities.VIBRATE_PATTERN);
Notification notification = mBuilder.build();
/* comment this out to stop the infinite notification loop */
notification.flags |= Notification.DEFAULT_LIGHTS
| Notification.FLAG_AUTO_CANCEL
| Notification.FLAG_ONLY_ALERT_ONCE;
Intent intent = new Intent(this, DashboardActivity.class);
PendingIntent activity = PendingIntent.getActivity(this, CommonUtilities.REQUEST_NOTIFICATION, intent, 0);
String pref = getSharedPreferences(CommonUtilities.NOTIFICATION_PEF, MODE_PRIVATE).getString("incoming", contentText);
notification.setLatestEventInfo(this, title ,pref, activity);
notification.number += 1;
//Display notification
notificationManager.notify(0, notification);