如何创建多重复警报。作为一个例子,我在下午4:30创建了一个警报,我想在每个星期日,星期一和星期四重复它。我可以安排定期闹钟,比如间隔后重复,但我怎么能做到这一点?
答案 0 :(得分:0)
您好,这是每月添加一次警报的示例。
private void setAlarmForOneMonth() {
AlarmManager mAlarmMgr = (AlarmManager) CONTEXT.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(CONTEXT, YOURALARMRECEIVERCLASS);
PendingIntent mAlarmIntent = PendingIntent.getBroadcast(CONTEXT, ONE_MONTH_ALARM, intent, PendingIntent.FLAG_UPDATE_CURRENT);
mAlarmMgr.set(AlarmManager.RTC_WAKEUP, getDuration(), mAlarmIntent);
}
private long getDuration(){
Calendar calendar = Calendar.getInstance();
int updatedMonthValue = calendar.get(Calendar.MONTH) + 1;
calendar.set(Calendar.MONTH, updatedMonthValue);
return calendar.getTimeInMillis(); // this is what you set as trigger point time i.e one month after
}
另外,您可以在此链接Alarm Manager
上阅读更多内容