如何在早上8:00设定的报警火灾日常生活

编程入门 行业动态 更新时间:2024-10-19 04:24:09
本文介绍了如何在早上8:00设定的报警火灾日常生活的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想设定一个闹钟每天都开火上午8:00。

我知道如何创建报警,但我将如何将其设置为每天推出日上午8:00。

am.setRepeating()

解决方案

您可以使用日历,并将其设置为您希望在适当的时候。然后,你会做 cal.getTimeInMillis(),并使用了triggerAtTime,且间隔为24 * 60 * 60 * 1000 = 86,400,000

您必须还要确保您有引导一个BroadcastReceiver完成,所以如果手机关机然后再打开,你可以重新安排报警:

  

注册的警报被保留,而在设备处于睡眠状态(并且可以   可选唤醒设备,如果他们在这段时间内熄灭),但   如果它被关闭并重新启动将被清除。

有关启动,您使用意图过滤器android.intent.action.BOOT_COMPLETED,你必须持有允许android.permission。 RECEIVE_BOOT_COMPLETED,以防万一你需要的信息。

为了您的方便,这里有几个链接。 日历上的页面:

developer.android/reference/java/util/Calendar.html

和上AlarmManager页面:

developer.android/reference/android/app/AlarmManager.html

那么,如何将看起来里面AlarmManager.setRepeating()?

下面的方法:

setRepeating(int型的,长triggerAtTime,间隔长,PendingIntent操作)

和我想的类型,您可能需要使用ELAPSED_REALTIME,然后让triggerAtTime,你会得到一个日历(称之为CAL)匹配上午8:00明天早上,然后执行

triggerAtTime = cal.getTimeInMillis() - Calendar.getInstance()getTimeInMillis()

那么这将是

alarmMan.setRepeating(AlarmManager.ELAPSED_REALTIME,triggerAtTime,86400000,pendingIntent);

和我不知道究竟是如何使用日历获得明天上午8点,但我想你会做 cal.getInstance(),然后 cal.add(Calendar.DAY,1)然后 cal.set(Calendar.HOUR_OF_DAY,8)

developer.android/reference/java/util/Calendar.html

我已经很少使用日历,所以我可能有一些错误,你可能有与它一点点打,但本质上需要做什么。在未来,如果你只是阅读文档,并与它的一些玩,你通常可以找到答案。

I am trying to set an alarm to fire everyday at 8:00am.

I know how to create the alarm, but how will i set it to launch everyday at 8:00am.

am.setRepeating()

解决方案

You could use Calendar and set it for the appropriate time that you want. Then you would do cal.getTimeInMillis(), and use that for the triggerAtTime, and the interval would be 24*60*60*1000 = 86,400,000

You would have to also make sure you have a BroadcastReceiver for boot completed, so if the phone is powered off then back on, you can re-schedule the alarm:

Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.

For boot, you use intent-filter "android.intent.action.BOOT_COMPLETED" and you must hold the permission "android.permission.RECEIVE_BOOT_COMPLETED", just in case you needed that info.

For your convenience, here are a couple links. The page on Calendar:

developer.android/reference/java/util/Calendar.html

And the page on AlarmManager:

developer.android/reference/android/app/AlarmManager.html

So how would that look inside AlarmManager.setRepeating()?

Here is the method:

setRepeating(int type, long triggerAtTime, long interval, PendingIntent operation)

And I guess for type, you would want to use ELAPSED_REALTIME, then to get triggerAtTime, you would get a Calendar (call it cal) that matched 8:00 AM tomorrow morning, then do

triggerAtTime = cal.getTimeInMillis()-Calendar.getInstance().getTimeInMillis()

Then it would be

alarmMan.setRepeating(AlarmManager.ELAPSED_REALTIME, triggerAtTime, 86400000, pendingIntent);

And I don't know how exactly to get tommorrow at 8:00 AM using Calendar, but I'm thinking you would do cal.getInstance(), then cal.add(Calendar.DAY, 1) then cal.set(Calendar.HOUR_OF_DAY, 8)

developer.android/reference/java/util/Calendar.html

I have hardly used Calendar, so I may have some errors, and you may have to play with it a little, but that's essentially what would need to be done. In the future, if you just read the DOCs and play with it some, you'll usually be able to figure it out.

更多推荐

如何在早上8:00设定的报警火灾日常生活

本文发布于:2023-11-27 04:10:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636533.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日常生活   火灾   早上   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!