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;
精彩评论