Android notification doesn't work properly -
i'm trying send notification @ specific time,set user via timepicker
. when run app first time , works, if change time of notification app send immediately. can't figure out why.
mainactivity code:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); pkg=getpackagename(); //intent openpage1 = new intent(mainactivity.this,impostazioni.class); //startservice(new intent(this, servicenot.class)); intent myintent = new intent(this , servicenot.class); alarmmanager alarmmanager = (alarmmanager)getsystemservice(alarm_service); pendingintent pendingintent = pendingintent.getservice(this, 0, myintent, 0); calendar calendar = calendar.getinstance(); sharedpreferences sharedpref = getsharedpreferences("hour",mode_private); notificah = sharedpref.getint("hour", 9); sharedpreferences sharedprefs = getsharedpreferences("second",mode_private); notificas = sharedprefs.getint("second", 10); calendar.set(calendar.hour_of_day, notifyh); calendar.set(calendar.minute, notifys); calendar.set(calendar.second, 00); long time=calendar.gettimeinmillis(); if(time<system.currenttimemillis()) { time=time+alarmmanager.interval_day; } alarmmanager.setrepeating(alarmmanager.rtc_wakeup, time, alarmmanager.interval_day , pendingintent); //set repeating every 24 hours
settings code:
public class impostazioni extends actionbaractivity { private switch myswitch; private switch sound; private textview viewora; private button btnsetora; int ora; int minuti; static final int time_dialog_id=0; public timepickerdialog mtimepicker; int notifyh=9; int notifys=00; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_impostazioni); myswitch = (switch) findviewbyid(r.id.myswitch); sound = (switch) findviewbyid(r.id.switch01); viewora = (textview) findviewbyid(r.id.viewora); btnsetora = (button) findviewbyid(r.id.btnimpostaora); sharedpreferences sharedpref = getsharedpreferences("hour",mode_private); notificah = sharedpref.getint("hour", 8); sharedpreferences sharedprefs = getsharedpreferences("second",mode_private); notificas = sharedprefs.getint("second", 01); viewora.settext( notifyh + ":" + notifys); btnsetora.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { calendar mcurrenttime = calendar.getinstance(); int hour = mcurrenttime.get(calendar.hour_of_day); int minute = mcurrenttime.get(calendar.minute); mtimepicker = new timepickerdialog(impostazioni.this, new timepickerdialog.ontimesetlistener() { @override public void ontimeset(timepicker timepicker, int selectedhour, int selectedminute) { viewora.settext( selectedhour + ":" + selectedminute); notifyh=selectedhour; notifys=selectedminute; sharedpreferences sharedpref = getsharedpreferences("hour",mode_private); sharedpreferences.editor prefeditor = sharedpref.edit(); prefeditor.putint("hour",notifyh); prefeditor.commit(); sharedpreferences sharedprefs = getsharedpreferences("second",mode_private); sharedpreferences.editor prefeditors = sharedprefs.edit(); prefeditors.putint("second",notifys); prefeditors.commit(); } }, hour, minute, true);//yes 24 hour time mtimepicker.settitle("select time"); mtimepicker.show(); } });
Comments
Post a Comment