java - Alarm manager not working properly -
i sending msg using alarm manager, alarm not working.if time 18hrs , set alarm 8 hrs sends msg right @ time. here code.
public class time_picker extends appcompatactivity { timepicker time_picker; string tag="pritesh"; static alarmmanager[] alarmmanager=new alarmmanager[5]; static pendingintent[] pendingintent = new pendingintent[5]; edittext message; edittext phone; intent myintent; // alarmmanager alarmmanager; //pendingintent pendingintent; public static string phone; public static string message; public int i; array ob=new array(); static arraylist<pendingintent> pendingarray=new arraylist<>(5); public void setalarm(view view) { // alarmmanager alarmmanager[]=new alarmmanager[5]; // if(prevention.timer==0) { phone = phone.gettext().tostring(); message = message.gettext().tostring(); phone.settext(""); message.settext(""); //validating if field empty if (phone.length() >= 10 && message.length() > 0) { toast.maketext(this.getapplicationcontext(), "your sms sent soon", toast.length_short).show(); //getting calender reference calendar cal = calendar.getinstance(); int currentapiversion = android.os.build.version.sdk_int; if (currentapiversion > android.os.build.version_codes.lollipop_mr1) { cal.set(calendar.minute, time_picker.getminute()); cal.set(calendar.hour_of_day, time_picker.gethour()); } else { //setting date , time time picker cal.set(calendar.minute, time_picker.getcurrentminute()); cal.set(calendar.hour_of_day, time_picker.getcurrenthour()); } int = (calendar.getinstance().get(calendar.second) * 1000); i=array.select; myintent = new intent(this, myreceiver.class); myintent.putextra("pos",array.select); //pending intent sending intent afterwards pendingintent[array.select] = pendingintent.getbroadcast(this.getapplicationcontext(), array.select, myintent, 0); alarmmanager[array.select] = (alarmmanager) (this.getsystemservice(context.alarm_service)); alarmmanager[array.select].set(alarmmanager.rtc, cal.gettimeinmillis() - a, pendingintent[array.select]); pendingarray.add(pendingintent[array.select]); sms_list.phone[array.select]=phone; intent = new intent(this, sms_list.class); back.putextra("phone", phone); back.putextra("flag",2); back.putextra("msg", message); back.putextra("hour", (int) cal.get(calendar.hour_of_day)); back.putextra("min", (int) cal.get(calendar.minute)); startactivity(back); //int b; } else { toast.maketext(this.getapplicationcontext(), "please fill details", toast.length_short).show(); array.a[array.select]=false; ob.sort(); } }
}
the code if set time has large difference doesnt work.
and can set alarm using 12 clock?
you cannot set alarm time passed.
alarmmanager[array.select].set(alarmmanager.rtc, cal.gettimeinmillis() - a, pendingintent[array.select]);
try future time below.
alarmmgr.set(alarmmanager.elapsed_realtime_wakeup, systemclock.elapsedrealtime() + 60 * 1000, alarmintent);
Comments
Post a Comment