Android 获取活动警报列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21949522/
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-08-20 05:21:40  来源:igfitidea点击:

Android get list of active alarms

androidalarm

提问by XylemRaj

Is there any way to get a list of all the active alarms in the android device programmatically in our application programmatically.Just point me out to some links that can be of help I am basically trying to give the user the facility of viewing all the alarms in his device so i want to get a list of all the active alarms in the device.

有没有什么方法可以在我们的应用程序中以编程方式获取 android 设备中所有活动警报的列表。请指出一些可以提供帮助的链接我基本上是在尝试为用户提供查看所有警报的便利在他的设备中,所以我想获得设备中所有活动警报的列表。

回答by Uncaught Exception

No, AFAIK you can't do that programmatically so showing that info to a user in UI is not feasible.

不,AFAIK 您不能以编程方式执行此操作,因此在 UI 中向用户显示该信息是不可行的。

However for your own reference you can dump the alarm data via

但是为了您自己的参考,您可以通过以下方式转储警报数据

adb shell dumpsys alarm

You don't need root permission for that.

您不需要 root 权限。

But what you get from above could be very confusing to understand. In order to understand that dump completely you should check out morphatic's answer here.

但是你从上面得到的东西可能很难理解。为了完全理解转储,您应该在此处查看 morphatic 的答案。

回答by Steven Trigg

Short answer: you can't.

简短的回答:你不能。

The alarm manager gives no visibility to the alarms currently scheduled in the system. Every app that uses alarm manager must persist the state of each alarm that they set.

警报管理器无法查看系统中当前安排的警报。每个使用警报管理器的应用程序都必须保持它们设置的每个警报的状态。

However you can get a list via adb as described in this question Get list of active PendingIntents in AlarmManager. And an app couldget a system dump and get the alarms that way but that would require root.

但是,您可以通过 adb获取列表,如本问题Get list of active PendingIntents in AlarmManager 中所述。应用程序可以获取系统转储并以这种方式获取警报,但这需要 root。

回答by Mena

If you mean by active alarms, the ones in the device's Alarm Clock Application, I think you can. Try checking out the methods from Here.

如果您的意思是主动警报,即设备的闹钟应用程序中的警报,我认为您可以。尝试查看Here 中的方法。

However, if you mean that you want to see all alarms created by AlarmManager on your device, then unfortunately you can not do it programatically.

但是,如果您的意思是希望在您的设备上查看由 AlarmManager 创建的所有警报,那么不幸的是,您无法以编程方式执行此操作。

But, you can view the dump data in a text file like this:

但是,您可以在文本文件中查看转储数据,如下所示:

adb shell dumpsys alarm > dump.txt

回答by ulcica

You can get the next alarm that is scheduled (docs)

您可以获得预定的下一个警报(文档)

getSystemService(AlarmManager::class.java).nextAlarmClock.triggerTime

Returns the time at which the alarm is going to trigger. This value is UTC wall clock time in milliseconds

返回警报将要触发的时间。此值是以毫秒为单位的 UTC 挂钟时间