Cha*_*ase 9 notifications android android-3.0-honeycomb progress-bar
我有一个在后台下载文件的持续通知.我已经成功创建了多个同时更新进度条通知,这些通知也可以取消.这适用于所有经过测试的设备,除了一些最近使用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);
Run Code Online (Sandbox Code Playgroud)
这是我更新通知的方式:
// 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);
Run Code Online (Sandbox Code Playgroud)
要解决此问题,您需要在正在进行的通知中设置按位Notification.FLAG_ONLY_ALERT_ONCE.这将确保仅在首次显示通知时通知用户.之后,他们必须打开通知托盘才能查看通知的状态.
Notification notification = new Notification();
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1561 次 |
| 最近记录: |