如果通知是离线发送的,Android是否可以检索FCM通知 [英] Is it possible for Android to retrieve FCM notification if the notification was sent when it was offline

查看:37
本文介绍了如果通知是离线发送的,Android是否可以检索FCM通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase云消息传递,我想知道是否可以将通知发送到脱机设备并在其联机后接收.

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.

我通过主题将通知发送到虚拟设备(Nexus 5 API 27)我使用以下依赖项:

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'

服务器端

我有一个发送POST请求的Java服务器:

Server side

I have a Java server that sends POST requests :

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

标题

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

身体

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

启动虚拟机后,我会很快收到通知.但是,如果我的虚拟设备已关闭并且我的服务器发送了通知,则即使等待超过1000万,客户端也不会收到通知.正常吗?我觉得我做错了什么,因为当我阅读文档时,通知应该被存储,直到有人阅读为止:

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

有人知道我是否犯了一个错误,或者我是否对FCM的功能计数过多?

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

谢谢.

推荐答案

那应该是正确的行为.当设备处于脱机状态或处于休眠状态时,它将在感觉需要时或在设备唤醒时将其交付. https://firebase.google.com/docs/cloud-messaging/concept-options#lifetime

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.

这篇关于如果通知是离线发送的,Android是否可以检索FCM通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆