android - How to retrive date and time from database and create notification on that particular date -
i want create reminder.i using below code generate notification @ particular time , date set user.
public class mainactivity extends activity { timepicker timepicker; datepicker datepicker; button button1; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); button1 = (button) findviewbyid(r.id.button1); button1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { timepicker = (timepicker) findviewbyid(r.id.timepicker1); datepicker = (datepicker) findviewbyid(r.id.datepicker1); alarmmanager alarmmanager = (alarmmanager) getsystemservice(alarm_service); calendar calendar = calendar.getinstance(); calendar.set(calendar.year, datepicker.getyear()); calendar.set(calendar.month, datepicker.getmonth()); calendar.set(calendar.day_of_month, datepicker.getdayofmonth()); calendar.set(calendar.hour_of_day, timepicker.getcurrenthour()); calendar.set(calendar.minute, timepicker.getcurrentminute()); calendar.set(calendar.second, 0); intent inn = new intent(mainactivity.this,alaramdetail.class); pendingintent displayintent = pendingintent.getactivity( getbasecontext(), 0,inn, 0); alarmmanager.set(alarmmanager.rtc_wakeup, calendar.gettimeinmillis(), displayintent); } }); } }
below alaramdetail class have code genrating notification.
public class alaramdetail extends activity { @suppresswarnings("deprecation") @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.detail); notificationmanager nm = (notificationmanager)getsystemservice(context.notification_service); notification notification = new notification(android.r.drawable.stat_notify_more, "this important notification",system.currenttimemillis()); string title = "pay attention"; string detail = "this implortant"; intent intent = new intent(alaramdetail.this,alaramdetail.class); finish(); pendingintent pintent = pendingintent.getactivity(alaramdetail.this, 0,intent ,0 ); notification.setlatesteventinfo(alaramdetail.this, title, detail, pintent); notification.flags=notification.flag_auto_cancel; notification.defaults|=notification.default_sound; notification.defaults|=notification.default_lights; notification.defaults|=notification.default_vibrate; nm.notify(1, notification); } }
above code working correctly. after doing have created database store multiple date , time inputted user.database store date , time string.now want generate notification @ particular date , time stored in database.i dont know how pass date , time database calendar.set(int field,int value) commands.i think can use cursor retrieving date , time dont know value pass in , args.my database has 3 columns name,date,time.
also better storing time in milliseconds long in database...it give better performance...
after retrieving data set time using code
calendar calender = calendar.getinstance(); calender.settimeinmillis(timeinmilli);
Comments
Post a Comment