java 检查我的应用程序的通知是否正在运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5286817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 10:25:16  来源:igfitidea点击:

Check if my application's notification is running

javaandroidnotifications

提问by kkudi

Is there a way I can check programatically whether my app's notification is currently running(shown)?

有没有办法以编程方式检查我的应用程序的通知当前是否正在运行(显示)?

That is to say that NotificationManager.notify()was invoked.

也就是说NotificationManager.notify()被调用了。

采纳答案by CommonsWare

Is there a way I can check programatically whether my app's notification is currently running(shown)?

有没有办法以编程方式检查我的应用程序的通知当前是否正在运行(显示)?

No.

不。

That is to say that NotificationManager.notify() was invoked.

也就是说 NotificationManager.notify() 被调用了。

You called notify(). Hence, you already know if notify()was called. You also know if your code calls cancel()or cancelAll(). You will also know, via the various PendingIntentsand flags, if the Notificationgoes away based upon user action. Hence, you have all of the information yourself to determine if the Notificationis on-screen or not.

你打电话给notify()。因此,您已经知道是否notify()被调用。您还知道您的代码是否调用cancel()cancelAll(). 您还将通过各种PendingIntents和 标志知道是否Notification根据用户操作消失。因此,您自己拥有所有信息来确定Notification屏幕上是否显示。

However, savvy developers will write their apps such that they do not care if their Notificationis on-screen or not.

然而,精明的开发人员会编写他们的应用程序,以便他们不关心他们Notification是否在屏幕上。

回答by Felipe

Is there a way I can check programatically whether my app's notification is currently running(shown)?

有没有办法以编程方式检查我的应用程序的通知当前是否正在运行(显示)?

Yes. Have a look on this: How to know when my notification is cleared via Clear button?

是的。看看这个:如何知道我的通知何时通过清除按钮被清除?

@octavian-damiean said:

@octavian-damiean 说:

It seems like you are looking for the deleteIntentfield of the Notificationclass.

看起来您正在寻找Notification类的deleteIntent字段 。

回答by Sam

You can in API 23 and above. Just call NotificationManager.getActiveNotifications().

您可以在 API 23 及更高版本中使用。就打电话吧NotificationManager.getActiveNotifications()