【发布时间】:2018-12-03 12:09:09
【问题描述】:
如果不是数据消息,则让 FCM 处理设备上的通知。
如何强制 Android 使用 FCM 显示通知,即使应用程序处于前台也是如此?我不想建立自己的通知。
我正在向我的应用程序发送两种类型的消息:数据消息和普通通知消息。数据消息在onMessageReceived() 中处理,无论应用程序是在后台还是前台还是被杀死,这是OK。但现在我也通过 Firebase 控制台发送正常的通知消息,当应用程序在后台时它们会自动显示,但当应用程序在前台时,会调用 onMessageReceived()。在这里,我需要以某种方式告诉 FCM 显示内容,而无需我构建通知。
我试过了:
@Override public void onMessageReceived(RemoteMessage remoteMessage) {
if(remoteMessage.getData() == null || !remoteMessage.getData().containsKey("specificKey")) {
// notification msg, let FCM handle it
super.onMessageReceived(remoteMessage); // this is not working - I want FCM to show notification the same as if the app was in background.
return;
} else {
// data message, I'm handling it on my own and showing a custom notification, working fine and well
}
}
但这是我自己通过代码进行的处理,我希望 FCM 以某种方式做到这一点。我该怎么做?
【问题讨论】:
-
我相信这是 Firebase 的一般行为。当应用程序处于前台时,您必须创建通知
标签: android firebase-cloud-messaging android-notifications