0

Alarm is not ringing on exact time and it is allowing to set in the pas time it should be set for the future not to less than current time I have tried logics but did not worked.

case R.id.alarm_on:
//setting calendar instance with the hour and minute that we picked
// on the timepicker

calendar.set(Calendar.HOUR_OF_DAY, alarm_timepicker.getHour());
calendar.set(Calendar.MINUTE, alarm_timepicker.getMinute());


getting integer value of hour and time
int hour = alarm_timepicker.getHour();
int minute = alarm_timepicker.getMinute();


convert the int values into strings
String hour_string = String.valueOf(hour);
String minute_string = String.valueOf(minute);


txthour.setText(hour_string);
txtminute.setText(minute_string);

convert into 12 hour format

if (hour > 12) {
hour_string = String.valueOf(hour - 12);
}
if (minute < 10) {
minute_string = "0" + String.valueOf(minute);
}

//METHOD THAT CHANGE THE UPDATE TEXTBOX
set_alarm_text("Alarm set to " + hour_string + ":" + minute_string);

//put extra string into my_intent
//tells the clock that you pressed the alarm button_on
my_intent.putExtra("extra", "alarm on");

//put extra long into my_intent
//tells the clock that you want a certain value from the dropdown menu 

my_intent.putExtra("whale_choice", choose_whale_sound);
//create the pending intent that delays the intent
//until the specified calendar time




pending_Intent = PendingIntent.getBroadcast(MainActivity.this, 0, my_intent,
PendingIntent.FLAG_UPDATE_CURRENT);

setting the alarm manager

alarm_manager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pending_Intent);
  • I have tried this link but it does not work for me – Arsalan Siddiqui Nov 22 '16 at 15:11
  • All you have to do is add `if(calendar.before(Calendar.getInstance())) { calendar.add(Calendar.DATE, 1); }` right before the `alarm_manager.setExact()` call. How does it not work for you? Be specific. – Mike M. Nov 22 '16 at 15:39

0 Answers0