I tried to set a default alarm schedule. it's working for exact time as well. but always i'm calling that function trigger the alarms without set time.
This is i tried code BroadcastReceiver, pendingIntent and alarmmanager.
public void DefaultAlert(){
int broadcast=0;
List<Time> times = new ArrayList<>();
times.add(new Time(7, 00));
times.add(new Time(9, 00));
times.add(new Time(11, 30));
times.add(new Time(13, 30));
times.add(new Time(15, 00));
times.add(new Time(17, 00));
times.add(new Time(20, 00));
times.add(new Time(22, 00));
Intent intent=new Intent(MainActivity.this,MyBroadcastReceiver.class);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
for (Time time : times){
PendingIntent pendingIntent=PendingIntent.getBroadcast(this.getApplicationContext(),broadcast++,intent,0);
Calendar cal_alarm=Calendar.getInstance();
cal_alarm.set(Calendar.HOUR_OF_DAY,time.hour);
cal_alarm.set(Calendar.MINUTE,time.minute);
cal_alarm.set(Calendar.SECOND,00);
Log.v(TAG,"Set Alarm For : "+time.hour+":"+time.minute);
// mOutputText.setText(TextUtils.join("\n",));
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
alarmManager.setExact(AlarmManager.RTC_WAKEUP,cal_alarm.getTimeInMillis(),pendingIntent);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal_alarm.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pendingIntent);
}
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT){
alarmManager.set(AlarmManager.RTC_WAKEUP,cal_alarm.getTimeInMillis(),pendingIntent);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal_alarm.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pendingIntent);
}
mOutputText.append(broadcast+". "+time.hour+":"+time.minute+"\n");
}
}
what is the reason for that? and give a solution.
Thank You