2

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

1 回答 1

3

嗯,你应该再次检查你的标志!

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

所以我的猜测是,有了这个标志,你的通知就会一直振动。

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

于 2013-08-25T19:21:04.737 回答