通知无限循环

时间:2013-08-25 19:16:35

标签: android notifications

每次发送通知时,设备的行为就像通知已被无限次发送一样。也就是说,铃声和振动不断响起,直到我打开通知菜单。如果我注释掉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);

1 个答案:

答案 0 :(得分:2)

嗯,你应该再次检查你的旗帜!

  

FLAG_ONLY_ALERT_ONCE
  如果您希望每次发送通知时都要播放声音和/或振动,即使在此之前未取消声音和/或振动,也应将位按位进入标志字段。

所以我的猜测是,通过这个标志,你会得到通知一直振动。

来自官方文档http://developer.android.com/reference/android/app/Notification.html