java - How to set repeated notification for specific day of week? -
i looking set notification on week days. have added string of days in alert dialog show days.
i want set day in calendar user has selected in alert dialog. also, should repeat next week on same day.
i have put time picker dialog choose time of notification. if c.gettime() , current date , time.
how set notification other days? if today monday , want create notification on wed? how can set wed in calendar?
c.set(calendar.hour_of_day, hour); c.set(calendar.minute, minute); c.set(calendar.second,0); c.set(calendar.millisecond,0); notification = c.gettime(); notificationtime = df.format(notification); notifytime.settext(notificationtime); toast.maketext(getapplicationcontext(),string.valueof(notification),toast.length_short).show();
for notification using alarm manager.
private void setalarm(calendar targetmcalen) { intent intent = new intent(getbasecontext(),notificationreceiver.class); pendingintent pendingintent = pendingintent.getbroadcast(getbasecontext(), rqs_1, intent, 0); alarmmanager alarmmanager = (alarmmanager)getsystemservice(context.alarm_service); alarmmanager.setinexactrepeating(alarmmanager.rtc_wakeup,targetmcalen.gettimeinmillis(), alarmmanager.interval_day *7, pendingintent); componentname receiver = new componentname(getapplicationcontext(),notificationreceiver.class); packagemanager pm = getapplicationcontext().getpackagemanager(); pm.setcomponentenabledsetting(receiver, packagemanager.component_enabled_state_enabled, packagemanager.dont_kill_app); toast.maketext(getapplicationcontext(),"notification set",toast.length_short).show(); }
alert dialog selecting day:
selectday.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { final alertdialog.builder builder = new alertdialog.builder(addeventactivity.this); builder.setsinglechoiceitems(r.array.day_array, -1, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int item) { string[] day = getbasecontext().getresources().getstringarray(r.array.day_array); selectday.settext(day[item]); dialog.dismiss(); } }); builder.show(); } });
do have set dayofweek in calendar instance inside alert dialog? like
c.set(calendar.day_of_week)?
edit :
i tried way. dose may going 1 day ahead every time if choose day multiple times.
selectday.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { final alertdialog.builder builder = new alertdialog.builder(addeventactivity.this); builder.setsinglechoiceitems(r.array.day_array, -1, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int item) { string[] day = getbasecontext().getresources().getstringarray(r.array.day_array); selectday.settext(day[item]); dayofweek = day[item]; switch (dayofweek) { case "mon": c.set(calendar.day_of_week,2); c.gettime(); toast.maketext(getapplicationcontext(),string.valueof(c.gettime()),toast.length_short).show(); break; case "tue": c.set(calendar.day_of_week, 3); c.gettime(); toast.maketext(getapplicationcontext(),string.valueof(c.gettime()),toast.length_short).show(); break; case "wed": c.set(calendar.day_of_week, 4); c.gettime(); toast.maketext(getapplicationcontext(),string.valueof(c.gettime()),toast.length_short).show(); break; case "thu": c.set(calendar.day_of_week, 5); c.gettime(); toast.maketext(getapplicationcontext(),string.valueof(c.gettime()),toast.length_short).show(); break; case "fri": c.set(calendar.day_of_week, 6); c.gettime(); toast.maketext(getapplicationcontext(),string.valueof(c.gettime()),toast.length_short).show(); break; case "sat": c.set(calendar.day_of_week, 7); c.gettime(); toast.maketext(getapplicationcontext(),string.valueof(c.gettime()),toast.length_short).show(); break; case "sun": c.set(calendar.day_of_week,1); c.gettime(); toast.maketext(getapplicationcontext(),string.valueof(c.gettime()),toast.length_short).show(); } dialog.dismiss(); } }); builder.show(); } });
please help..
public class timerreceiver extends broadcastreceiver { public void schedulealarms(context paramcontext) { calendar calendar = calendar.getinstance(); if (strmytime.contains("one week")) { calendar.set(calendar.date, 7); registerreceiver(paramcontext, calendar, alarmmanager.interval_day * 7); } } public void registerreceiver(context paramcontext, calendar calender, long interval) { alarmmanager localalarmmanager = (alarmmanager) paramcontext.getsystemservice(context.alarm_service); pendingintent localpendingintent = pendingintent.getservice(paramcontext, 0, new intent(paramcontext, notificationservice.class), pendingintent.flag_update_current); localalarmmanager.setrepeating(alarmmanager.rtc, calender.gettimeinmillis(), interval, localpendingintent); } @override public void onreceive(context context, intent intent) { schedulealarms(context); context.startservice(new intent(context, notification.class)); }
}
Comments
Post a Comment