我正在使用此代码广播特定日期的警报。但它每天都在响。任何人都可以帮助我吗?
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);
答案 0 :(得分:0)
如果您只想安排一次:
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
如果你想每周重复一次:
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(), alarmManager.INTERVAL_DAY * 7, pendingIntent);
设置日历变量时请务必小心。根据DOCS:
对于set()
如果声明的触发时间是过去的,则会触发警报 立即。如果已安排此Intent的警报 (两个意图的相等性由...定义 filterEquals(Intent)),然后它将被删除并替换为this 之一。
适用于setRepeating()
如果规定的触发时间是过去的,则会立即触发警报,警报计数取决于触发时间相对于重复间隔的过去程度。