我的闹钟管理器一天多次触发。我想在每天早上8点开一次。
这是我的代码。
Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,0, intent,0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar firingCal = Calendar.getInstance();
Calendar currentCal = Calendar.getInstance();
firingCal.set(Calendar.HOUR_OF_DAY,8);
firingCal.set(Calendar.MINUTE,00);
firingCal.set(Calendar.SECOND,00);
firingCal.set(Calendar.AM_PM, Calendar.AM);
if(firingCal.getTimeInMillis()>=currentCal.getTimeInMillis()){
//set from today
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,firingCal.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pendingIntent);
}else{
//set for next day
firingCal.add(Calendar.DAY_OF_MONTH, 1);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,firingCal.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pendingIntent);
}