6

when i sent Firebase Topic notification, onMessageReceived method is not fire when application is in

  1. Background and screen lock
  2. Application is close from recent application

in above two case i got notification only in system tray, i want to handle it programmatically in store in sqlite

same question i think

and its work in case application in foreground and background while listed in recent applications

So how i get thats notification , i want store 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
}

thanks in advance

Community
  • 1
  • 1
HiteshGs
  • 539
  • 2
  • 7
  • 18
  • I have same problem is any one have solution then answer it....thanks.... – Subhash Khimani Sep 16 '16 at 08:46
  • yes @SubhashKhimani thats possible you need to send push notification with "Data" so when you send push and if you app is close event if you receive notification in receiver, make sure you add receiver correctly – HiteshGs Sep 17 '16 at 05:15

2 Answers2

1

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

Instead, always send the notification with data tag. This will ensure that all the FCM messages trigger the onMessageReceived call. In this call, you can save the message inside a db as per usual android methods.

Summary: Only send the data tag and no notification tag. Handle showing and saving the notification inside onMessageReceived(). Works whether the app is in foreground or background or killed.

Warning: If you are planning an IOS launch, FCM message with data tag will only get delivered if the app is in foreground or backgrounded but not killed yet. Until then no messages will be received.

Kushan
  • 5,855
  • 3
  • 31
  • 45
0

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

Check this link it is mentioned that , there are two ways so send message payload.

1) As Notification

2) As Data

If server send "Data" payload, then it will receive in the application onMessageReceived() method. And you can manage it in onMessageReceived() by checking the payload as given 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 do server code, passing 'notification' / 'data'.

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

hims_3009
  • 1,737
  • 14
  • 23