Android:在FCM中接收消息的延迟(onMessageReceived) [英] Android: Delay in Receiving message in FCM(onMessageReceived)

查看:336
本文介绍了Android:在FCM中接收消息的延迟(onMessageReceived)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在测试应用程序中,我已经实现了FCM以使用

In Test app, I have implemented FCM for sending notification messages using

https://github.com/firebase/quickstart-android/tree/掌握/发消息

为了进行测试,我使用Notification(通知)下的"New Message"(新消息)从Firebase控制台发送了消息( 8:42 PM ).

For testing I sent the message(8:42 PM) from firebase console using the "New Message" under Notification.

但是在我的模拟器中,我是在 9:06 PM

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.

谢谢.

推荐答案

这可能是由于Firebase Cloud Messaging中的不切实际的心跳间隔引起的.

This could be caused by the unrealistic heartbeat intervals in Firebase Cloud Messaging.

FCM通过维持从Android设备到Google服务器的空闲套接字连接来工作.这非常好,因为它几乎不消耗电池电量(与轮询相反),并且允许在消息到达时立即唤醒设备.

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.

为确保连接保持活动状态,Android将在移动连接上每28分钟发送一次心跳,在WiFi上每15分钟发送一次心跳.如果心跳失败,则连接已终止,FCM将重新建立连接并尝试检索任何未决的推送通知.心跳间隔越大,消耗的电池越少,必须从睡眠中唤醒设备的次数就越少.

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.

但是,这要付出很大的代价:心跳间隔越长,识别断开的套接字连接所花费的时间就越长.在部署FCM之前,Google尚未在实际情况中对这些间隔进行充分的测试.这些间隔的问题是由网络路由器和移动运营商造成的,它们在闲置几分钟后断开空闲的套接字连接.

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 /

作为一种解决方法,请考虑使用Pushy( https://pushy.me ),它是GCM的替代产品/FCM,可大大提高通知速度和可靠性(全面披露-我创立了Pushy).

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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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