我有一个持续的后台下载通知。我成功创建了多个同时更新的进度条通知,这些通知还可以被取消。在所有已测试设备上都能正常工作,但在某些较新的 Android 平板电脑(带有 Honeycomb 系统)上无法正常运行。
现在的问题是原始通知消息不断重新显示,导致用户无法单击时钟以呼出正在进行的通知列表。因此,甚至看不到任何进度条。是否有人成功地在 Honeycomb 上创建进度条通知?
另外,我发现黑色通知文本在通知列表的黑色背景上不再可读。是否有方法为 Honeycomb 设备设置白色文本?
注意:这已在运行 Android 3.0.1 的 Optimus Pad L-06C 和 Motorola Xoom 上进行了测试。
以下是通知创建内容:
现在的问题是原始通知消息不断重新显示,导致用户无法单击时钟以呼出正在进行的通知列表。因此,甚至看不到任何进度条。是否有人成功地在 Honeycomb 上创建进度条通知?
另外,我发现黑色通知文本在通知列表的黑色背景上不再可读。是否有方法为 Honeycomb 设备设置白色文本?
注意:这已在运行 Android 3.0.1 的 Optimus Pad L-06C 和 Motorola 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);