AlarmManger に問題があります:
以下は 1 日を正しく追加します (時間 9:25 が経過したため) 出力は正しいですが、AlarmManager は数秒以内にブロードキャストを呼び出します。関連するスニピットは次のとおりです。何か案は?
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 21);
cal.set(Calendar.MINUTE, 25);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Intent intent = new Intent(this, NotificationReceiver.class);
NotificationReceiver instance = new NotificationReceiver();
intent.setAction(instance.NOTIFICATION_SEND);
intent.putExtra("TYPE",instance.NOTIFICATION_TYPE_PROGRESS);
intent.putExtra("Ticker","Waiting for arrival.");
intent.putExtra("ID",1);
intent.putExtra("title","Check-In");
intent.putExtra("message","A message");
if(System.currentTimeMillis()>cal.getTimeInMillis()){
if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY||cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY||cal.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY){
cal.add(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
Log.d("ALARMS","Set for monday.");
}
else{
cal.add(Calendar.DATE,1);
Log.d("ALARMS","Set for tomorrow. "+cal.get(Calendar.DAY_OF_MONTH));
}
}
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 24332, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),4000,pendingIntent);