android - Firebase Save Notification to DB not working when app is not running -


i handling fcm notifications in app. in

public void onmessagereceived(remotemessage remotemessage) {          notification notification = new notification();         notification.settitle(remotemessage.getnotification().gettitle());         notification.setdescription(remotemessage.getnotification().getbody());         dateformat simpledateformat = new simpledateformat("dd/mm/yyyy");         dateformat simpletimeformat = new simpledateformat("hh:mm");         date date = new date(remotemessage.getsenttime());          notification.settime(simpletimeformat.format(date));         date date2 = new date();         notification.setdate(simpledateformat.format(date2));         databasehelper databasehelper = new    databasehelper(getapplicationcontext());         databasehelper.savenotification(notification);          //calling method generate notification         sendnotification(remotemessage.getnotification().getbody());     } 

but when app not running or in background mode not able save notifications.

i using "regular activity" processing , display of notifications in app.

as said in this link

don't know missing.

firebase notifications in android not sent registered messages service when app in background , notification contains notification key. ensure service handles notifications, don't use notification field. instead use data field purpose.

actually 1 downside of using firebase's notification field cannot specify large , small icons system tray notification. lets set 1 icon.

note not "universal" solution since ios users not receive notification in background when there's no notification field present.

having said that, think best solution right send android users notification following:

{     "to":"tht4d...",     "data":     {         "title":"nice title",         "body":"nice body"     } } 

and handle in service this:

public void onmessagereceived(remotemessage remotemessage) {     map<string, string> data = remotemessage.getdata();     makemycustomnotification(data.get("title"), data.get("body")); } 

for ios users use standard way:

{     "to":"tht4d...",     "notification":     {         "title":"nice title",         "body":"nice body"     } } 

there's big discussion around topic here


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -