【问题标题】:Ongoing notification on Android honeycomb has inconsistent behaviorAndroid 蜂窝上的持续通知具有不一致的行为
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

  • 你是我的英雄!此标志上的 cmets 读取“如果您希望每次发送通知时都播放声音和/或振动,即使在此之前尚未取消,也应按位或将位按位或设置到标志字段中。”所以这可能就是我从未尝试过使用它的原因。谢谢!
【解决方案2】:

如果有人还在寻找,我想我发现了这个问题。问题是当您创建新通知时,时间设置为当前系统时间。如果你看一下:http://developer.android.com/reference/android/app/Notification.html#when,你会读到下载操作应该在开始时被标记。如果您不这样做(就像我所做的那样)并且您有多个下载通知,它们将继续根据 when 字段重新排序。

【讨论】:

    【解决方案3】:

    通知列表在GB上没有黑色背景;只有状态栏变成了黑色。什么设备导致了问题?您是否在标准 GB 上尝试过此操作,以确保这不是特定于该设备的问题,而不是平台中发生更改的问题?你知道这个设备是不是兼容CDD并通过了CTS?

    【讨论】:

    • 我知道我应该提到这个模型。我目前正在使用运行 Android 3.0.1 的 Optimus Pad L-06C。我还没有测试过任何其他设备,但我一拿到手就会测试。我不熟悉此设备是否符合 CDD 标准。我将使用相关信息更新问题。谢谢。
    • 另外,当我指的是 Honeycomb 时,我错误地将 Gingerbread。我现在已经在两台设备上验证了这一点。
    • 啊,是的,作为 Android 3.0 中新 UI 的一部分,背景发生了变化。这个关于堆栈溢出的答案应该会有所帮助:stackoverflow.com/questions/4867338/…
    • 但是您是否已经解决了您的第一个问题,即多个持续通知?
    【解决方案4】:

    为了解决这个问题(在 4.0.3 上,没有尝试以前的 API 级别)我必须保留对我的 Notification 的引用,每次发生变化时更新它,然后将相同的 Notification 对象发送到 @ 987654323@.

    尽管我按照@twaddingtion 的答案中指定的方式设置flags,并将相同的id 发送到NotificationManager,但我的通知在SystemBar 中却搞砸了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-10
      相关资源
      最近更新 更多