Firebase message with high priority not waking device from Doze android 6+

前端 未结 8 1315
一整个雨季
一整个雨季 2020-12-07 19:07

I have migrated my project from using GCM to use Firebase. Push notification comes through ok when the device is awake or been asleep recently but if I leave the device for

相关标签:
8条回答
  • 2020-12-07 19:40

    Setting a time_to_live of 0 solved the problem for me.

    I think it's because a very small time_to_live will tell FCM that this message is only worth delivering right this instant. So in an attempt to deliver it ASAP, it will ignore battery optimizations like the Android P's "app standby buckets". Be careful though, as setting a small time_to_live might mean not delivering the notification at all in some cases. I don't think you should be applying it to all kinds of push notifications.

    For more details about time_to_live: https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message

    0 讨论(0)
  • 2020-12-07 19:41

    There is nothing you can do.

    This is a known issue that is caused by a battery optimization implemented by some OEMs (like Meizu or Asus). When an app is swiped away in the app switcher, the application is treated as if it were Force stopped, which is not the default Android behavoir. The unfortunate side effect of this is that it can cause the FCM service for your app to stop running. Similar effect can be caused on high priority messages in doze mode.

    Firebase team is working to improve this behavior from their end but the actual fix has to come from OEM side.

    One way to check if your app is affected by any OEM's battery management feature, is as below:

    1) Attach the OEM device to adb

    2) Run your app on the device

    3) Swipe the app away from recent screen on the device

    4) Run command: adb shell dumpsys package MY-PACKAGE | grep stopped

    If it shows stopped=true, it's safe to assume that the OEM has such a mechanism and that your app is affected by the same.

    0 讨论(0)
提交回复
热议问题