简体   繁体   中英

Is it possible for Android to retrieve FCM notification if the notification was sent when it was offline

I'm using firebase cloud messaging, and I'd like to know if it's possible to send a notification to an offline device and receive it after it comes online afterward.

Client side

I send notifications via topics to a virtual device (Nexus 5 API 27) I use the following dependencies :

compile 'com.google.firebase:firebase-auth:11.8.0'
compile 'com.google.firebase:firebase-core:11.8.0'
compile 'com.google.firebase:firebase-database:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'

Server side

I have a Java server that sends POST requests :

URL : https://fcm.googleapis.com/v1/projects/PROJECT_ID/messages:send

Headers

Authorization : Bearer <token OAuth2>
Content-Type : application/json

Body

{
    "message": {
        "topic":"topicName",
        "data": {
            "infoKey": "infoValue",
        }
    }
}

When the virtual machine is started I receive the notification quickly. But if my virtual device is shut down and my server sends a notification, the client doesn't receive the notification even after waiting more than 10mn. Is it normal ? I feel like I did something wrong because when I read the documentation the notification is supposed to be stored until someone reads it :

https://firebase.google.com/docs/cloud-messaging/concept-options#ttl

Does anyone knows if I made a mistake or perhaps do I count too much on the feature of FCM ?

thank you.

That should be the correct behavior. When the device is offline or in doze it will deliver it as soon as it feels like it needs to or when the device wakes up. https://firebase.google.com/docs/cloud-messaging/concept-options#lifetime

You could try playing around with priorities to see if that delivers notifications faster once the device is turned on, if you need it to be as soon as possible.

You are going good.

But As off now Google do not provide any history feature on user basis.

I can suggest a simple approach to this problem. You can keep a record of the notifications you send to users at server end. At users end, whenever notification is received maintain another record.

And whenever user goes online just tally both the records and fetch missing records using restful service. You can use various parameters for tallying the records like timestamp, tokens, etc.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM