i want to set an alarms every day of weeks at mighnight this is my code:
int notificationId = getNotificationId(); //it get a random number
Context context = rule.context;
Intent intent = ((Activity) context).getIntent();
long time = getRuleCalendar().getTimeInMillis();
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, time, pendingIntent);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, time,pendingIntent);
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, time,pendingIntent);
}
public calendar getRuleCalendar(){
Calendar calSet = Calendar.getInstance();
calSet.set(Calendar.DAY_OF_WEEK, calendarDay); //calendarDay change by day of weeks
calSet.set(Calendar.HOUR_OF_DAY, 0);
calSet.set(Calendar.MINUTE, 0);
calSet.set(Calendar.SECOND, 0);
calSet.set(Calendar.MILLISECOND, 1);
return calSet
}
now my problem is that one alarm start immediately (now is after mighnight and it is ok for me i want to check today) but all other alarms start at wrong time. why?