【发布时间】:2018-09-17 06:33:17
【问题描述】:
我正在制作一个 VoIP 应用程序。即使应用程序在后台,如何确保来电通知? Google FCM 仅在应用程序处于前台时才有效(可能是由于 android 电池优化)。 Whatsapp 和 Telegram 做了什么来确保近 100% 的来电通知?
当应用在后台时,onMessageReceived 方法不会被调用。
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getData().toString());
}
}
附言 在浏览Telegram's codebase 时,我发现他们总是在前台运行他们的应用程序
<service android:name=".BringAppForegroundService" android:enabled="true"/>
他们是这样解决通知的,还是有更多的东西?
【问题讨论】:
-
您在 Firebase 通知响应中尝试过仅数据消息吗?
-
@DäñishShärmà 是的,尝试过
user.sendCloudMessage({customData: data, priority: "high"})。数据在哪里{ "sinch": { ... "PushData": pushData, ... } } -
我也遇到了同样的问题,你找到这个问题的真正原因了吗?数据消息并不总是在小米/华为手机中传递,但电报/WhatsApp 通话正常。
标签: android firebase push-notification firebase-cloud-messaging android-notifications