기본적으로이 코드가 있습니다. 시간은 24 시간을 반환하고 매일 알람을 반복합니다.AlarmManager가 같은 날에 설정된 시간을 지나서 알람을 울리면 setRepeating
public setAlarm(String time, Context context){
String[] strTime;
strTime = time.split(":");
int hour, min, sec;
//set when to alarm
hour = Integer.valueOf(strTime[0]);
min = Integer.valueOf(strTime[1]);
sec = 0;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, min);
cal.set(Calendar.SECOND, sec);
//Create a new PendingIntent and add it to the AlarmManager
Intent intent = new Intent(context, AlarmReceiverActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 19248, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
}
어쨌든, 문제는 오전 9시 10 분에 알람 9am을 설정하면 알람이 울리는 것입니다. 왜? 시스템 시간이 지나면 알람이 울리지 않도록하고 싶습니다. 전의. 시스템 시간이 오전 9시 10분
AlarmManager.INTERVAL_DAY +1 - 왜 +1을 추가합니까? –
"알람이 지연된 경우 (예 : 시스템 알람이 아닌 유형의 경우 _ WAKEUP 알람 유형) 가능한 한 빨리 건너 뛴 반복이 전달됩니다. 이후에 원래 알람에 따라 앞으로의 알람이 전달됩니다. 시간이 흐르면 표류하지 않는다.예를 들어 매시간 상위 알람 알람을 설정했지만 전화가 7:45에서 8:45까지 잠 들어있는 경우 전화기가 깨어나 자마자 알람이 전송되고 다음 알람이 보내집니다 9시. "그래서 같은 날에 알람을 설정하면 알람이 울릴 것입니다. – FeanDoe