Search code examples
androidfirebasemessaging

Firebase Cloud Messaging onDeletedMessages() not called


My Android app uses Firebase Cloud Messaging to send data messages, and it's been working fine. Now I'm implementing onDeletedMessages(), but I can't get my test case to call it. The message being sent is:

{
  "priority": "high",
  "to": "/topics/test",
  "time_to_live": 0,
  "data": {
    "sites": [
      {
        "plusMD5": "959d4d57d19a2047a2e75fccfb9a1512",
        "plus": [
          "abcderf:r"
        ],
        "site": "computers"
      }
    ],
    "time": 1500660817
  }
}

To test:

  1. Set the device to Airplane Mode
  2. Send the data message
  3. Wait a bit (15 seconds or so)
  4. Turn off Airplane Mode

Now that the device has a network connection again, I'd expect onDeletedMessages() to be called, but it's not. Am I misunderstanding how FCM handles deleted and missed messages, or could something else be going on? Thanks!

Rob


Solution

  • Interesting..

    The docs here : https://firebase.google.com/docs/cloud-messaging/android/receive#override-ondeletedmessages

    said that In some situations, FCM may not deliver a message. This occurs when there are too many messages (>100) pending for your app on a particular device at the time it connects or if the device hasn't connected to FCM in more than one month. In these cases, you may receive a callback to FirebaseMessagingService.onDeletedMessages()

    So you need to fullfill these 2 conditions :

    1. Need to send (>100) notification where the device is offline
    2. Turn on Airplane Mode for more than one month