android show notification with a popup on top of any application -
with below code notification added notification bar, no popup style message displayed if receive whatsapp message when you're in application. makes happen notification?
private void sendnotification(int distance, viewobject viewobject) { intent notificationintent = new intent(getapplicationcontext(), mainactivity.class); notificationintent.addflags(intent.flag_activity_new_task | intent.flag_activity_single_top); notificationintent.putextra("path", viewobject.getpath()); taskstackbuilder stackbuilder = taskstackbuilder.create(this); stackbuilder.addparentstack(mainactivity.class); stackbuilder.addnextintent(notificationintent); pendingintent notificationpendingintent = stackbuilder.getpendingintent(integer.parseint(viewobject.getrefid()), pendingintent.flag_update_current); notificationcompat.bigtextstyle bigtext = new notificationcompat.bigtextstyle(); bigtext.bigtext(string.format(getstring(r.string.notification), viewobject.gettitle())); bigtext.setbigcontenttitle(getstring(r.string.hello)); notificationcompat.builder builder = new notificationcompat.builder(this); builder.setsmallicon(r.drawable.ic_wald_poi) .setlargeicon(bitmapfactory.decoderesource(getresources(), r.drawable.ic_poi)) .setcolor(getresources().getcolor(r.color.primary)) .setcontenttitle(getstring(r.string.hello)) .setcontentintent(notificationpendingintent) .setcontenttext(string.format(getstring(r.string.notification), viewobject.gettitle())) .setdefaults(notification.default_all) .setstyle(bigtext); builder.setautocancel(true); notificationmanager mnotificationmanager = (notificationmanager) getsystemservice(context.notification_service); mnotificationmanager.notify(0, builder.build()); }
if want use heads-up notifications
this:
set notification priority notification.priority_high
or notification.priority_max
notificationcompat.builder builder = new notificationcompat.builder(this); builder.setsmallicon(r.drawable.ic_wald_poi) .setlargeicon(bitmapfactory.decoderesource(getresources(), r.drawable.ic_poi)) .setcolor(getresources().getcolor(r.color.primary)) .setcontenttitle(getstring(r.string.hello)) .setcontentintent(notificationpendingintent) .setcontenttext(string.format(getstring(r.string.notification), viewobject.gettitle())) .setdefaults(notification.default_all) .setstyle(bigtext) .setpriority(notification.priority_high);
here more info :-)
Comments
Post a Comment