i want schedule notification according date (the date postscheduleddate
) , notification before postscheduleddate
, amount of time of before
1 min in code.
i tried this:
//here converting postscheduleddate milliseconds long postscheduledlong = postscheduleddate.gettime(); // , here converting system time millisecond long systemscurrenttime = system.currenttimemillis(); // , here getting difference between system time , postscheduled time long differnecetoadd = systemscurrenttime - postscheduledlong; // here converting difference int can put int value method int delayint = differnecetoadd.intvalue(); // here subtracting difference of time 1 min can // show notification before scheduled time of post int oneminutebefore = delayint - 60000; // method takes amount of difference in integer form // , add amount of time system's time, // on added time shows notification schedulenotification(getnotification("10 second delay"), oneminutebefore);
and here method showing notification:
private void schedulenotification(notification notification, int delay) { intent notificationintent = new intent(this, notificationpublisher.class); notificationintent.putextra(notificationpublisher.notification_id, 1); notificationintent.putextra(notificationpublisher.notification, notification); pendingintent pendingintent = pendingintent.getbroadcast(this, 0, notificationintent, pendingintent.flag_update_current); // here adding difference of time scheduling notification long futureinmillis = systemclock.elapsedrealtime() + delay; log.v("remindertime = "+futureinmillis, ""); alarmmanager alarmmanager = (alarmmanager)getsystemservice(context.alarm_service); alarmmanager.set(alarmmanager.elapsed_realtime_wakeup, futureinmillis, pendingintent); }
i don't know why not getting notification know method working fine cause tried hardcodes 1min
, 30sec
etc.
it turns out simple tried
string[] posttypearray = new string[]{"1 hour before", "6 hour before", "1 day before"}; new materialdialog.builder(this) .title("set reminder") .items(posttypearray) .itemscallback(new materialdialog.listcallback() { @override public void onselection(materialdialog dialog, view view, int which, charsequence text) { if (which == 0) { calendar cal = calendar.getinstance(); cal.settime(postscheduleddate); cal.add(calendar.hour, -1); long onehourback = cal.gettimeinmillis(); schedulenotification(getnotification( datestr ,""+titlestr), onehourback); toast.maketext(getbasecontext(), "reminder has been setted " + text, toast.length_short).show(); } else if (which == 1) { calendar cal = calendar.getinstance(); cal.settime(postscheduleddate); cal.add(calendar.hour, -1); long onehourback = cal.gettimeinmillis(); schedulenotification(getnotification( datestr ,""+titlestr), onehourback); toast.maketext(getbasecontext(), "reminder has been setted " + text, toast.length_short).show(); } else if ( == 2){ calendar cal = calendar.getinstance(); cal.settime(postscheduleddate); cal.add(calendar.hour, -1); long onehourback = cal.gettimeinmillis(); schedulenotification(getnotification( datestr ,""+titlestr), onehourback); toast.maketext(getbasecontext(), "reminder has been setted " + text, toast.length_short).show(); } } }) .show();
here materialdialog
dialog builder assume listview different options selecting time notification
Comments
Post a Comment