Android 通知会随着某些标志而持续进行

发布于 2024-10-10 04:24:21 字数 1354 浏览 8 评论 0原文

好吧,

可能是 android 的另一个奇怪的未记录的怪癖,但我在向我的通知添加标志时发现了一些很奇怪的东西...

如果我这样做:

  Notification notification = new Notification(R.drawable.status_icon, "[Ticker Text]",System.currentTimeMillis());

  PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, CarparkScreen.class), 0);

  notification.setLatestEventInfo(AlertService.this,"[Title]", "[Detail]", intent);

  mNM.notify(NOTIFICATION_BREACH, notification);

那么通知将显示为一次性的,单击取消是,您可以在其中清除它正常的方式。

然而,如果我添加这些标志,

  Notification notification = new Notification(R.drawable.status_icon, "[Ticker Text]",System.currentTimeMillis());

  PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, CarparkScreen.class), 0);

  notification.setLatestEventInfo(AlertService.this,"[Title]", "[Detail]", intent);

  notification.flags = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS;

  mNM.notify(NOTIFICATION_BREACH, notification);

它会创建一个持续通知,尽管没有持续标志!

我认为实际上是 DEFAULT_VIRBATE 标志导致了这种情况,起初我认为这是因为我没有振动权限,但我现在添加了它,但它仍然导致通知持续存在。

呃!!!!

其他人可以重新创建这个吗?看起来如此明显的用例是一个错误或怪癖。

我实际上在尝试创建上面的非持续通知的同时使用持续通知,但这确实不应该导致这种情况,因为我正在使用除NotificationManager之外的所有内容的新实例。上述代码中的ID也与正在进行的通知不同。

任何想法非常感谢! :)

安迪。

Ok,

Possibly another bizare undocumented quirk of android, but I'm finding something quite odd when adding flags to my notification...

If I do this:

  Notification notification = new Notification(R.drawable.status_icon, "[Ticker Text]",System.currentTimeMillis());

  PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, CarparkScreen.class), 0);

  notification.setLatestEventInfo(AlertService.this,"[Title]", "[Detail]", intent);

  mNM.notify(NOTIFICATION_BREACH, notification);

Then the notification appears as a one off, clicking cancels is and you can clear it in the normal way.

If however I add these flags

  Notification notification = new Notification(R.drawable.status_icon, "[Ticker Text]",System.currentTimeMillis());

  PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, CarparkScreen.class), 0);

  notification.setLatestEventInfo(AlertService.this,"[Title]", "[Detail]", intent);

  notification.flags = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS;

  mNM.notify(NOTIFICATION_BREACH, notification);

It creates an ongoing notification, despite there being no ongoing flag!!

I think its actually the DEFAULT_VIRBATE flag which is causing this, which at first I though was because I didn't have vibrate permissions, but I've added that now but it still causes the notification to be ongoing.

Urgh!!!!

Can anyone else re-create this? Seems such an obvious use case to be a bug or quirk.

I am actually using an ongoing notification at the same time as trying to create a non-ongoing notification above, but this really shouldn't cause this as I'm using new instances of everything apart from the NotificationManager. The ID in the above code is also different to the ongoing notification.

Any ideas muchly appreciated! :)

Andy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睫毛溺水了 2024-10-17 04:24:21

它会创建一个持续通知,尽管没有持续标志!!

flags 字段获取 FLAG_ 常量。 defaults 字段获取 DEFAULT_ 常量。您将 DEFAULT_ 常量放入 flags 字段中。尝试更改您的代码以使用 defaults 字段。

It creates an ongoing notification, despite there being no ongoing flag!!

The flags field gets FLAG_ constants. The defaults field get DEFAULT_ constants. You are putting DEFAULT_ constants in the flags field. Try changing your code to use the defaults field.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文