android - AlarmManager not working with time picker -
i have service.. have generate notification @ time taken time picker.. working system.currenttimemillis()
, not if take time time picker
here time picker showing on click of textview:
tv.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub mcurrenttime = calendar.getinstance(); int hour = mcurrenttime.get(calendar.hour_of_day); int minute = mcurrenttime.get(calendar.minute); timepickerdialog mtimepicker; mtimepicker = new timepickerdialog(mainactivity.this, new timepickerdialog.ontimesetlistener() { @override public void ontimeset(timepicker timepicker, int selectedhour, int selectedminute) { timepicker.setis24hourview(true); //tv.settext( selectedhour + " : " + selectedminute); mcurrenttime.set(calendar.hour,selectedhour); mcurrenttime.set(calendar.minute,selectedminute); mcurrenttime.set(calendar.second,0); // here getting time timepicker l= mcurrenttime.gettimeinmillis(); tv.settext(string.valueof(l)); } }, hour, minute, true);//yes 24 hour tim mtimepicker.settitle("select time"); mtimepicker.show(); } });
here code of button click, on click starting service:
intent myintent = new intent(mainactivity.this, myreceiver.class); int randompin = (int)(math.random()*9000)+1000; pendingintent = pendingintent.getbroadcast(mainactivity.this, randompin, myintent,pendingintent.flag_one_shot); alarmmanager alarmmanager = (alarmmanager)getsystemservice(alarm_service); //here entering time time picker alarmmanager.set(alarmmanager.rtc, l , pendingintent);
replace this:
mcurrenttime.set(calendar.hour, selectedhour);
with this:
mcurrenttime.set(calendar.hour_of_day, selectedhour);
calendar.hour strictly 12 hours.
as per documentation
field number , set indicating hour of morning or afternoon. hour used 12-hour clock (0 - 11). noon , midnight represented 0, not 12. e.g., @ 10:04:15.250 pm hour 10.