Is it possible to save a notification about saving a Firebase theme in sqlite when the application is closed in android

when I sent a notification about the Firebase theme, the onMessageReceived method does not work when the application is in

  • Background and lock screen
  • App close to recent app

in two cases, I received a notification only in the system tray, I want to process it programmatically in the store in sqlite

the same question i think

and its work if the application in the foreground and in the background is indicated in recent applications

So, as I receive this notification, I want to save the notification in sqlite

my postman request is below

{ "to": "/topics/181_Red_Route", "data": { "sound": "default", "badge": "1", "title": "Title1", "body": "Desc1" }, "notification": { "sound": "default", "badge": "1", "title": "Title1", "body": "Desc1" }, "priority": "high", "content_available": true } 

early

+5
source share
3 answers

https://firebase.google.com/docs/cloud-messaging/android/send-multiple

Check this link that there are two ways to send a message.

1) As Notice

2) Data

If the server sends "Data" , then it will receive onMessageReceived () in the application. And you can manage it in onMessageReceived () by checking the payload as shown below.

 // Check if message contains a data payload. if (remoteMessage.getData().size() > 0) { Log.d(TAG, "Message data payload: " + remoteMessage.getData()); } // Check if message contains a notification payload. if (remoteMessage.getNotification() != null) { Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); } 

& Also check how to execute server code by passing "notification" / "data".

https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages

0
source

Hi guys, I also have the same problem with my Android application when the application is in the background at this time onMessageReceived method does not work

0
source

If you send a notification tag inside an FCM message, it will not call the onMessageReceived code when the application is in the background.

Instead, always send a notification with a data tag. This ensures that all FCM messages trigger the onMessageReceived call. In this call, you can save the message inside db according to the usual Android methods.

Summary Just send the data tag and notification tag. The handle shows and saves the notification inside onMessageReceived (). Whether the application is running in the foreground or in the background or killed.

A warning. If you plan to launch IOS, an FCM message with a data tag will be delivered only if the application is in the foreground or focused, but not yet killed. Until then, no messages will be received.

0
source

All Articles