android - Can't get a notification to show -


can't status bar notifications work... followed this guide, , created following code in asynctask, it's called doinbackground() method:

private void newnotification(int count) {     notificationcompat.builder builder = new notificationcompat.builder(handler.getcontext());     builder.setcontenttitle("new notification");     builder.setcontenttext("testing notification");     builder.setnumber(count);      // creates explicit intent activity in app     intent intent = new intent(handler.getcontext(), mainactivity.class);      // stack builder object contain artificial stack     // started activity.     // ensures navigating backward activity leads out of     // application home screen.     taskstackbuilder stackbuilder = taskstackbuilder.create(handler.getcontext());      // adds stack intent (but not intent itself)     stackbuilder.addparentstack(mainactivity.class);      // adds intent starts activity top of stack     stackbuilder.addnextintent(intent);     pendingintent pendingintent = stackbuilder.getpendingintent(0, pendingintent.flag_update_current);     builder.setcontentintent(pendingintent);     notificationmanager notificationmanager = (notificationmanager) handler.getcontext().getsystemservice(context.notification_service);     notificationmanager.notify(0, builder.build()); } 

handler reference mainactivity, using interface implements getcontext(), returns this.getcontext() of mainactivity

for reason when call parameter 1, nothing happens.

@override protected string[] doinbackground(string... empty) {     newnotification(1);     return null; }    

debug shows lines of code running, no notifications appear. didn't find mention of special permission, or needs run ui thread anywhere. assume doesn't since background services meant notify... when message arrives.

any ideas did wrong?

1) have tried posting ui thread?

2) because services default run in ui thread unless explicitly put in seprate thread.

3) why don't try simple example first, like:

notificationcompat.builder builder = new notificationcompat.builder(handler.getcontext()); builder.setcontenttitle("new notification"); builder.setcontenttext("testing notification"); builder.setnumber(count); builder.setsmallicon(r.drawable.ic_launcher);  intent notificationintent = new intent(this, yourclass.class); notificationintent.setflags(intent.flag_activity_brought_to_front); pendingintent contentintent = pendingintent.getactivity(this, 0, notificationintent, 0); notification.setlatesteventinfo(getapplicationcontext(), "hello", "hello", contentintent);  mnotificationmanager.notify(1, builder.build()); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -