9

我有一个正在进行的后台下载文件的通知。我已成功创建多个同时更新进度栏通知,这些通知也可以取消。这在所有测试设备上都能正常工作,除了一些最近使用Honeycomb的Android平板电脑。Android蜂窝上的持续通知具有不一致的行为

现在,原始通知消息不断重新显示,防止用户点击时钟以显示正在进行的通知列表。因此,甚至没有看到进度条。有没有人成功地在Honeycomb上创建进度条通知?

作为一方,我还发现我的黑色通知文本在通知列表的黑色背景中不再可读。有没有为蜂窝设备设置白色文本的方法?

注:这一问题已经在运行Android 3.0.1的擎天柱垫L-06C和摩托罗拉XOOM

下面测试是通知创造

// Create new notification for downloading 
mNotification = new Notification(R.drawable.owl_icon, getNotificationText(R.string.notification_content_downloading), 0); 
mNotification.flags |= (Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT); 

// Create custom progress bar view 
RemoteViews contentView = new RemoteViews(CourseSyncService.this.getPackageName(), R.layout.notification_downloading); 
contentView.setTextViewText(R.id.notificationTitle, mCourseTitle); 
contentView.setProgressBar(R.id.notificationProgressBar, 100, 0, false); 
contentView.setTextViewText(R.id.notificationPercentage, "0%"); 
mNotification.contentView = contentView; 

// Create pending intent for the notification 
Intent notificationIntent = new Intent(CourseSyncService.this, CancelDownloadActivity.class); 
notificationIntent.putExtra(CourseSyncService.KEY_USER_ID, mUserId); 
notificationIntent.putExtra(CourseSyncService.KEY_COURSE_ID, mCourseId); 
notificationIntent.putExtra(CourseSyncService.KEY_COURSE_TITLE, mCourseTitle); 
PendingIntent contentIntent = PendingIntent.getActivity(CourseSyncService.this, mCourseId, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); 
mNotification.contentIntent = contentIntent; 

// Launch notification 
mNotificationManager.notify(mCourseId, mNotification); 

这里是我如何更新通知:

// Update the progress bar of the notification view 
mNotification.contentView.setProgressBar(R.id.notificationProgressBar, mItemCount, mProgressCount, false); 
mNotification.contentView.setTextViewText(R.id.notificationPercentage, String.valueOf(mProgress) + "%"); 
mNotificationManager.notify(mCourseId, mNotification); 
+1

通知(ID,通知)有文档指出在同一个ID上通知“将被更新的信息替换”。似乎Honeycomb增加了一个可怕的重新显示,在以前的版本没有发生。 – Rene 2011-08-07 19:19:55

+1

恭喜超过1500!我的投票推动了你的边缘......但主要是感谢问这个问题,我有同样的问题,并修复了这个问题。 – JPM 2012-03-22 22:53:13

+0

呜呼!谢谢! – Chase 2012-03-23 00:07:35

回答

7

要解决此问题,您需要在正在进行的通知中设置按位Notification.FLAG_ONLY_ALERT_ONCE。这将确保只有在第一次显示通知时才会通知用户。之后,他们将不得不打开通知盘以查看通知的状态。

Notification notification = new Notification(); 
notification.flags |= Notification.FLAG_ONGOING_EVENT; 
notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; 
+0

你是我的英雄!如果您希望每次发送通知时都播放声音和/或振动,即使在此之前没有取消声音,该标志上的注释也会显示“Bit要按位进入应设置的标志字段。”所以这可能是为什么我从来没有尝试过使用它。谢谢! – Chase 2011-08-26 08:11:44

+0

这似乎不适用于我... NexusS 4.0.3 – 2012-06-20 15:31:59

0

通知列表在GB上没有黑色背景;只有状态栏变为黑色。什么设备造成麻烦?你有没有在标准GB上试过这个,以确保这不是特定于该设备的问题,而是在平台上发生了变化?你知道这个设备是否与CDD兼容并通过了CTS?

+0

我知道我应该提到这个模型。我目前正在使用运行Android 3.0.1的Optimus Pad L-06C。我没有用任何其他设备进行测试,但只要我拿到一个手就可以了。我不太清楚这个设备是否符合CDD标准。我将用相关信息更新问题。谢谢。 – Chase 2011-06-06 05:55:39

+0

另外,我错误地把姜饼,当我的意思是蜂窝。我现在已经在两台设备上验证了这一点。 – Chase 2011-06-08 09:57:03

+1

是的,作为Android 3.0新UI的一部分,背景发生了变化。这个堆栈溢出的答案应该有所帮助:http://stackoverflow.com/questions/4867338/custom-notification-layouts-and-text-colors – hackbod 2011-06-23 16:33:58

0

为了解决这个问题(在4.0.3,以前的API水平没有尝试),我不得不引用保持我Notification,每次有变化时更新它,然后发送相同Notification对象NotificationManager.notify()

Altough我设置了flags在@ twaddingtion的回答指定的,发送相同idNotificationManager我通知了在SystemBar越来越混乱。