编写以下代码并解释。唤醒设备在下午2点左右发出警报并同时每天重复一次。唤醒设备以准时上午8:30发出警报,此后每20分钟发出警报。设备重启时启动警报。
你应该阅读Android's training samples他们逐字回答这两个问题。我会在这里提供一个样本,但你应该自己查看第二个样本,这样你才能真正了解正在发生的事情。
// Set the alarm to start at approximately 2:00 p.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 14);
// With setInexactRepeating(), you have to use one of the AlarmManager interval
// constants--in this case, AlarmManager.INTERVAL_DAY.
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, alarmIntent);