Firebase onMessageReceived not called when app in background

前端 未结 26 3105
粉色の甜心
粉色の甜心 2020-11-22 02:32

I\'m working with Firebase and testing sending notifications to my app from my server while the app is in the background. The notification is sent successfully, it even appe

26条回答
  •  春和景丽
    2020-11-22 03:08

    The backend I'm working with is using Notification messages and not Data messages. So after reading all the answers I tried to retrieve the extras from the bundle of the intent that comes to the launched activity. But no matter which keys I tried to retrieve from getIntent().getExtras();, the value was always null.

    However, I finally found a way to send data using Notification messages and retrieve it from the intent.

    The key here is to add the data payload to the Notification message.

    Example:

    {
        "data": {
            "message": "message_body",
            "title": "message_title"
        },
        "notification": {
            "body": "test body",
            "title": "test title"
        },
        "to": "E4An.."
    }
    

    After you do this, you will be able to get your info in this way:

    intent.getExtras().getString("title") will be message_title

    and intent.getExtras().getString("message") will be message_body

    Reference

提交回复
热议问题