我使用此代码来广播特定日期的警报。但它每天都在响。有人能在这方面帮我吗?
calendar.set(Calendar.HOUR_OF_DAY, hours);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.DAY_OF_WEEK, weekdayList.get(x));
Intent myIntent = new Intent(getApplicationContext(), AlarmReceiver.class);
myIntent.putExtra("reminder_id",value+"");
myIntent.putExtra("reminder_title", title.getText().toString());
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), value1, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);
// alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(), 1000 * 60 * 60, pendingIntent);
发布于 2016-03-02 22:26:02
如果您只想安排一次:
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
如果你想每周重复一次:
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(), alarmManager.INTERVAL_DAY * 7, pendingIntent);
请记住,在设置日历变量时要小心。根据DOCS的说法:
set()的
如果所述触发时间已经过去,则立即触发告警。如果已经为该意图计划了一个警报(两个意图的相等由filterEquals( Intent )定义),那么它将被删除并被这个警报替换。
用于setRepeating()的
如果所述的触发时间是过去的时间,则立即触发警报,警报计数取决于过去的触发时间相对于重复间隔的距离。
https://stackoverflow.com/questions/35758092
复制