java - Sending the notifications from service -


the implementation of notification sending work if send activity, nothing happens if send service. can suggest possible solutions? thanks

here service implementation..........

public class myservice extends service {  private notificationmanager notificationmanager; private dbhelper dbhelper; private sqlitedatabase db; private context mcontext = this;  private int notificationid = 100;  @override public void oncreate() {     log.i("mylogs", "service: oncreate()");     super.oncreate();     dbhelper = new dbhelper(this);     db = dbhelper.getwritabledatabase();     notificationmanager = (notificationmanager)getsystemservice(notification_service); }  @override public int onstartcommand(intent intent, int flags, int startid) {      log.i("mylogs", "service: onstartcommand()");      simpledateformat dateformat = new simpledateformat("yyyy-mm-dd");     date date = new date();     string currentdatestring = dateformat.format(date);      simpledateformat timeformat = new simpledateformat("hh-mm");     date time = new date();     string currenttimestring = timeformat.format(time);      string[] columns = {dbhelper.date, dbhelper.time, dbhelper.event};     cursor cursor = db.query(dbhelper.table_name, columns, null, null, null, null, null);     cursor.movetofirst();     {         string datestring = cursor.getstring(cursor.getcolumnindex(dbhelper.date));         string timestring  = cursor.getstring(cursor.getcolumnindex(dbhelper.time));         string eventstring = cursor.getstring(cursor.getcolumnindex(dbhelper.event));         boolean datecompare = currentdatestring.equals(datestring);         boolean timecompare = currenttimestring.equals(timestring);         if((datecompare) && (timecompare)) {             notify(eventstring, "message");         }         if(cursor.movetolast()) {             cursor.movetofirst();         }     }while(true);      //return super.onstartcommand(intent, flags, startid); }  @override public ibinder onbind(intent intent) {     return null; }  @override public void ondestroy() {     super.ondestroy(); }    private void notify(string notificationtitle, string bodytext){      notificationmanager notificationmanager = (notificationmanager) getsystemservice(notification_service);     @suppresswarnings("deprecation")      notification notification = new notification(r.drawable.ic_launcher, "new message", system.currenttimemillis());      intent notificationintent = new intent(this, mainactivity.class);      notificationintent.addflags(intent.flag_activity_single_top | intent.flag_activity_clear_top);     pendingintent pendingintent = pendingintent.getactivity(this, notificationid, notificationintent, 0);      notification.setlatesteventinfo(getapplicationcontext(), notificationtitle, bodytext, pendingintent);     notification.flags |= notification.flag_auto_cancel;     notificationmanager.notify(notificationid++, notification); } } 


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -