我正在构建一个使用警报管理器的应用程序。用户设置日期和时间,有 7 个复选框,一周中的每一天一个,他们勾选的闹钟将在这些日子响起。就像我知道您可以将日期和时间放入警报管理器中一样,有什么方法可以将日期和时间放入警报管理器中,并且它们会在每周的那一天响起?
最佳答案
AlarmManager.setRepeating作为参数:
type One of ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP}, RTC or RTC_WAKEUP.
在这里你需要 RTC 或 RTC_WAKEUP
triggerAtTime Time the alarm should first go off, using the appropriate clock (depending on the alarm type).
这里给出第一次闹钟的日期/时间(我相信这一定是UTC时间,所以要小心)
Calendar calendar = new GregorianCalendar(2011, Calendar.APRIL, 19, 23, 12);
long firstTime = calendar.getTimeInMillis();
interval Interval between subsequent repeats of the alarm.
要每周重复,您将给出整周的毫秒数作为间隔:
long interval = 1000 * 60 * 60 * 24 * 7;
或
long interval = 7 * AlarmManager.INTERVAL_DAY;
关于android - 在某些日子设置安卓闹钟管理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5715940/