android - Firebase notification message is not displayed on tray icon? -


i'me using this example integrate firebase cloud messaging app. sending messages via firebase console, both target user segment , topic (topic news) works. app display toast contains message.

what want notification message, automatically displayed in android notification tray, not toast. after reading fcm concept, tried curl:

curl -h "content-type: application/json" -h "authorization:key=aaaa....ahjkdkhajksd"  -x post -d '{ "to": "/topics/news", "notification": { "body":"foo", "title":"bar", "icon":""}}' https://fcm.googleapis.com/fcm/send 

it displayed via toast though, not android notification tray. go possibly wrong here?

notifications not shown automatically notification bar in case app in foreground. if want app show notification if app in foreground need add following code.

myfirebasemessagingservice.java

public class myfirebasemessagingservice extends firebasemessagingservice {  @override public void onmessagereceived(remotemessage remotemessage) {     jsonobject object = new jsonobject(remotemessage.getdata());     try {         string title = object.getstring("title");         string message = object.getstring("message");          intent intent = new intent(getbasecontext(), mainactivity.class);         pendingintent contentintent = pendingintent.getactivity(getbasecontext(), 0, intent, pendingintent.flag_update_current);          notificationcompat.builder b = new notificationcompat.builder(getbasecontext());          b.setautocancel(true)                 .setdefaults(notification.default_all)                 .setwhen(system.currenttimemillis())                 .setsmallicon(r.drawable.ic_launcher)                 .setticker("ticker")                 .setcontenttitle(title)                 .setcontenttext(message)                 .setdefaults(notification.default_lights | notification.default_sound)                 .setcontentintent(contentintent)                 .setcontentinfo("info");          random r = new random();         int randomno = r.nextint(100000000 + 1);          notificationmanager notificationmanager = (notificationmanager) getbasecontext().getsystemservice(context.notification_service);         notificationmanager.notify(randomno, b.build());     } catch (jsonexception e) {         e.printstacktrace();     }     super.onmessagereceived(remotemessage); } } 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

Ansible warning on jinja2 braces on when -