本文介绍了如何在早上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,以防万一你需要的信息。

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

http://developer.android.com/reference/java/util/Calendar.html

和上AlarmManager页面:

http://developer.android.com/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)

http://developer.android.com/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:

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:

http://developer.android.com/reference/java/util/Calendar.html

And the page on AlarmManager:

http://developer.android.com/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)

http://developer.android.com/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设定的报警火灾日常生活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 04:10