Android 通知会随着某些标志而持续进行
好吧,
可能是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
flags
字段获取FLAG_
常量。defaults
字段获取DEFAULT_
常量。您将DEFAULT_
常量放入flags
字段中。尝试更改您的代码以使用defaults
字段。The
flags
field getsFLAG_
constants. Thedefaults
field getDEFAULT_
constants. You are puttingDEFAULT_
constants in theflags
field. Try changing your code to use thedefaults
field.