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

前端 未结 8 1314
一整个雨季
一整个雨季 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:18

    It looks like it is not possible to make high priority while sending only data field without notification. Here is the quote from documentation:

    High priority messages generally should result in user interaction with your app or its notifications. If FCM detects a pattern in which they don't, your messages may be de-prioritized.

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

    After struggling with a similar issue I managed to get it to work.

    I send following json data through postman:

    {
      "data": {
        "body": "Test body from curl"
      },
      "registration_ids": ["Token"],
      "webpush": {
        "headers": {
          "Urgency": "high"
        }
      },
      "android": {
        "priority": "high"
      },
      "priority": 10
    }
    

    It seems like the last "priority":10 is what's fixing it for me.

    I could not find any reference to this in the Firebase documentation, but in the deprecated GCM documentation it's used. https://developers.google.com/cloud-messaging/concept-options

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

    While working on an application, I am also stuck at this point. Then I found a issue about it on Github, which solved my problem. That is,

    On devices running Android 6.0+, Doze mode terminates all background connections when the phone is idle and not being charged, including the background connection to Pushy.

    As soon as the device is moved or awoken by the user, background connections are restored and any pending notifications will be delivered within seconds, providing they have not expired yet.

    To send notifications to devices in Doze mode, your app can declare the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission in its AndroidManifest.xml and display a system dialog that asks users to whitelist your app from battery optimizations without leaving the app.

    This will effectively keep the background connection to Pushy active and devices will be able to receive notifications even in Doze mode.

    You can check this issue here https://github.com/ToothlessGear/node-gcm/issues/231

    Hope it helps you!

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

    Instead of using "android":{"priority":"high"}, use like this

        {
          "time_to_live": 300000,
          "delay_while_idle": false,
          "data": {
                   "message": "PING_DEVICE",
                   "time": "21/01/2018 16:20:28",
                   "pushguid": "10062"
                   },
          "priority": "high"  
    }
    
    0 讨论(0)
  • 2020-12-07 19:28

    TL;DR - make sure to set the notification priority correctly based on the JSON payload structure for FCM's legacy HTTP protocol vs its HTTP v1 protocol.

    There may already be sufficient answers from posts above based on your circumstance or implementation, but I wanted to provide an answer with more context based on the distinction between the legacy HTTP and HTTP v1 protocols that FCM provides in their documentation, but there is a subtle difference between the two protocol APIs when setting notification priority.

    Our team experienced the same problem of not receiving push notifications on Android 6+ devices that have Doze enabled even though our server was seemingly setting the priority correctly in the FCM API payload that similar to the payload provided in the original question. We rely on Amazon SNS to forward payloads to FCM, and the payload sent from our server to Amazon SNS would set the priority based on the AndroidConfig JSON object:

    {
        "android": {
            "priority": "high"
        }
    }
    

    However, this is only correct according to the HTTP v1 protocol. What we didn't realize is that Amazon SNS is likely still using the legacy HTTP protocol where the priority has to be set at the top-level of the JSON payload:

    {
        "priority": "high", // legacy HTTP protocol (this can also be set to 10)
        "android": {
            "priority": "high" // HTTP v1 protocol
        }
    }
    

    Thus, the notification priority would only take effect and enable push notifications to be received while in Doze when the legacy HTTP priority parameter was set to "high" or 10.

    For context, these are the API endpoints for each protocol when sending messages to FCM:

    • Legacy HTTP: https://fcm.googleapis.com/fcm/send
      • Requires top-level "priority" param (see here)
    • HTTP v1: https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send
      • Requires "android" object with "priority" param (see here)
    0 讨论(0)
  • 2020-12-07 19:28

    Thanks for the replies everyone. we finally sorted it.

    We logged into the firebase console and realized due to the age of the code we did not use a settings/config file that is generated in the console. sorry i've forgotten the name of it. this file has settings etc which are used when pushes are sent to google. once we used the file in our requests, my application can wake up a phone in doze.

    thanks

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