开发者

Setting android alarm manager on certain days

开发者 https://www.devze.com 2023-02-27 04:44 出处:网络
I\'m building an app that uses alarm manager. The user sets day and time and there is 7 checkboxs, one for each day of the week and the ones they tick the alarm will go off on them days. Like i know y

I'm building an app that uses alarm manager. The user sets day and time and there is 7 checkboxs, one for each day of the week and the ones they tick the alarm will go off on them days. Like i know you can put date a开发者_JS百科nd time into the alarm manager is there any way i can put like day and time into alarm manager and them it will go off on that day every week?


AlarmManager.setRepeating takes as parameter:

type One of ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP}, RTC or RTC_WAKEUP.

Here you will want RTC or RTC_WAKEUP

triggerAtTime Time the alarm should first go off, using the appropriate clock (depending on the alarm type).

Here you give the date/time of the first alarm (I believe this must be UTC time, so be careful)

Calendar calendar = new GregorianCalendar(2011, Calendar.APRIL, 19, 23, 12);
long firstTime = calendar.getTimeInMillis();

interval Interval between subsequent repeats of the alarm.

To repeat every week, you will give as interval the number of milliseconds in a whole week:

long interval = 1000 * 60 * 60 * 24 * 7;

or

long interval = 7 * AlarmManager.INTERVAL_DAY;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号