Display firebase notification data-message on Android tray -


i need use non-collapsible notification firebase. using data-message this:

{  "to" : "bk3rnwte3h0:ci2k_hhwgipodkcizvvdmexudfq3p1...",  "data" : {    "nick" : "mario",    "body" : "great match!",    "room" : "portugalvsdenmark"   }, } 

this message interpreted in onmessagereceived() method. still want display data-message in tray notification-messages displayed system automatically.

how achieve this? cannot find documentation on this.

thanks!

you can retrieve values data payload in onmessagereceived() calling remotemessage.getdata(), .get("<key_here>"). so:

public void onmessagereceived(remotemessage remotemessage) {         super.onmessagereceived(remotemessage);         log.d(tag, "onmessagereceived()");          // check if message contains data payload.         if (remotemessage.getdata().size() > 0) {             log.d(tag, "message data payload: " + remotemessage.getdata());              string datatitle = remotemessage.getdata().get("data_title");             string databody = remotemessage.getdata().get("data_body");              sendnotification(datatitle, databody); } 

you have build , display notification yourself. so:

private void sendnotification(string title, string body) {         notification notif = new notificationcompat.builder(this)                 .setsmallicon(r.mipmap.ic_launcher)                 .setcontenttitle(title)                 .setcontenttext(body)                 .build();          notificationmanagercompat notificationmanager = notificationmanagercompat.from(this);         notificationmanager.notify(0, notif); } 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -