【发布时间】:2011-06-06 03:17:01
【问题描述】:
我有在后台下载文件的持续通知。我已经成功地创建了多个同时更新的进度条通知,这些通知也可以被取消。这在所有经过测试的设备上都可以正常工作,除了一些最新的带有 Honeycomb 的 Android 平板电脑。
现在的效果是原始通知消息不断重新显示,防止用户单击时钟以调出正在进行的通知列表。因此,甚至看不到进度条。有没有人成功地在 Honeycomb 上创建进度条通知?
另一方面,我还发现我的黑色通知文本在通知列表的黑色背景下不再可读。有没有办法为 Honeycomb 设备设置白色文本?
注意:这已经在运行 Android 3.0.1 和 Motorola Xoom 的 Optimus Pad L-06C 上进行了测试
下面是通知创建
// 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);
【问题讨论】:
-
notify(id, notification) 有文档说明在同一 id 上,通知“将被更新的信息替换”。似乎 Honeycomb 增加了一个可怕的重新显示,这在以前的版本中没有发生。
-
恭喜超过1500!我的投票把你推到了边缘......但主要感谢你提出这个问题,我遇到了同样的问题,这解决了它。
标签: android notifications progress-bar android-3.0-honeycomb