Firebase onMessageReceived not called when app is inactive

前端 未结 5 1109
醉话见心
醉话见心 2021-01-22 05:23

I am using Firebase Cloud Messaging on Android.

  • I can successfully receive notification and data messages when the app is in the foreground.
  • The documen
5条回答
  •  旧时难觅i
    2021-01-22 06:01

    The problem is in your backend. See this answer. When the message contains notification object, onMessageReceived is called only when the app is foreground. So you have to use only data object. Eg:

    var message = {
             to: user.deviceId, // required
             collapse_key: 'key',
             data: {
                  title: 'Hello',
                  body: 'Body'
             }
    }; 
    

    This works for every scenario.

提交回复
热议问题