Setting android alarm manager on certain days

后端 未结 1 1077
既然无缘
既然无缘 2021-02-06 18:26

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 t

1条回答
  •  暖寄归人
    2021-02-06 19:08

    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 讨论(0)
提交回复
热议问题