java - Alarm Manager and system time -
i want time time picker comparing system time. if both times compared , equal want show toast "time reached". have tried code. not working. calling toast before time reached. plus not working when app closed. suggestions or approach?
if(code.contentequals("1")) { toast.maketext(getapplication(), "before hour: " + calendar.get(calendar.hour_of_day), toast.length_long ).show(); toast.maketext(getapplication(), "befor min: " + calendar.get(calendar.minute), toast.length_long ).show(); toast.maketext(getapplicationcontext(), "am pm "+ calendar.get(calendar.am_pm), toast.length_short).show(); done.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (build.version.sdk_int >= build.version_codes.m) { hour = timepicker.gethour(); toast.maketext(getapplicationcontext(), "if hour:" + hour, toast.length_short).show(); } else { hour = timepicker.getcurrenthour(); toast.maketext(getapplicationcontext(), "else hour:" + hour, toast.length_short).show(); } if (build.version.sdk_int >= build.version_codes.m) { min = timepicker.getminute(); } else min = timepicker.getcurrentminute(); if (hour < calendar.get(calendar.hour_of_day)) /// selected hour < current hour put am_pm = else am_pm=pm { am_pm = 0; am_pm = "am"; } else { am_pm = 1; am_pm = "pm"; } toast.maketext(getapplicationcontext(), "hour:" + hour, toast.length_short).show(); calendar mycalendar = calendar.getinstance(); /// toast.maketext(getapplicationcontext(), "hour:"calendar.set(calendar.hour_of_day, hour), toast.length_short).show() /// mycalendar.set(calendar.hour_of_day, hour); mycalendar.set(calendar.minute, min); mycalendar.set(calendar.second, 00); mycalendar.set(calendar.am_pm, am_pm); mycalendar.set(calendar.hour_of_day, hour); toast.maketext(getapplication(), "selected hour: " + mycalendar.get(calendar.hour_of_day), toast.length_long).show(); toast.maketext(getapplication(), "selected min: " + mycalendar.get(calendar.minute), toast.length_long).show(); toast.maketext(getapplication(), "selected pm " + mycalendar.get(calendar.am_pm), toast.length_long).show(); intent intent = new intent(getapplicationcontext(), timereciver.class); pendingintent pendingintent = pendingintent.getbroadcast(getapplicationcontext(), 234324243, intent, pendingintent.flag_update_current); alarmmanager alarmmanager = (alarmmanager) getapplicationcontext().getsystemservice(activity.alarm_service); alarmmanager.set(alarmmanager.rtc_wakeup, calendar.gettimeinmillis(), pendingintent); if (hour > 12) time1 = hour - 12 + ":" + min + " " + am_pm; else time1 = hour + ":" + min + " " + am_pm; sharedpreferences.editor time1 = sharedpreferences.edit(); time1.putstring("time1", time1); time1.apply(); time1.commit(); toast.maketext(getapplication(), "you selected: " + time1, toast.length_long).show(); } }); }
Comments
Post a Comment