在测试应用中,我实现了 FCM 以使用
发送通知消息但在我的模拟器中,我在 9:06 PM
收到了消息如果有什么办法可以减少延迟,请告诉我.
谢谢.
这可能是由 Firebase Cloud Messaging 中的不切实际的心跳间隔引起的.
FCM 的工作原理是维持从 Android 设备到 Google 服务器的空闲套接字连接.这很棒,因为它几乎不消耗电池电量(与轮询相反),并且它允许在消息到达时立即唤醒设备.
为确保连接保持活动状态,Android 将在移动连接上每 28 分钟发送一次检测信号,在 WiFi 上每 15 分钟发送一次检测信号.如果心跳失败,则连接已终止,FCM 将重新建立它并尝试检索任何未决的推送通知.心跳间隔越高,消耗的电池越少,设备从睡眠中唤醒的次数就越少.
但是,这是有代价的:心跳间隔越长,识别断开的套接字连接所需的时间就越长.在部署 FCM 之前,Google 尚未在现实生活中对这些间隔进行足够彻底的测试.这些间隔的问题是由网络路由器和移动运营商造成的,它们会在几分钟不活动后断开空闲套接字连接.
更多信息可以在我的博客上找到:
http://eladnava.com/google-cloud-messaging-extremely-unreliable/
作为一种解决方法,请考虑 Pushy (https://pushy.me),它是 GCM 的直接替代品/FCM 大大提高了通知速度和可靠性(完全披露 - 我创立了 Pushy).
In Test app, I have implemented FCM for sending notification messages using
https://github.com/firebase/quickstart-android/tree/master/messaging
For testing I sent the message(8:42 PM) from firebase console using the "New Message" under Notification.
But in my emulator, I have received the message at 9:06 PM
Please let me know if there is anything to do reduce the delay.
Thank you.
This could be caused by the unrealistic heartbeat intervals in Firebase Cloud Messaging.
FCM works by maintaining an idle socket connection from an Android device to Google’s servers. This is great because it barely consumes battery power (contrary to polling), and it allows the device to be woken up instantly when a message arrives.
To make sure that the connection remains active, Android will send a heartbeat every 28 minutes on mobile connection and every 15 minutes on WiFi. If the heartbeat failed, the connection has been terminated, and FCM will re-establish it and attempt to retrieve any pending push notifications. The higher the heartbeat interval, the less battery consumed and the less times the device has to be woken up from sleep.
However, this comes at a great price: the longer the heartbeat interval, the longer it takes to identify a broken socket connection. Google has not tested these intervals in real-life situations thoroughly enough before deploying FCM. The problem with these intervals is caused by network routers and mobile carriers, who disconnect idle socket connections after a few minutes of inactivity.
More info is available on my blog:
http://eladnava.com/google-cloud-messaging-extremely-unreliable/
As a workaround, please consider Pushy (https://pushy.me), a drop-in replacement for GCM/FCM which greatly improves notification speed & reliability (Full disclosure - I founded Pushy).
这篇关于Android:FCM中接收消息的延迟(onMessageReceived)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!