[英]Check for new notifications on Firebase Cloud Messaging. (FCM)
Am looking for a way of reading or listening to changes if at all am connected on firebase cloud messaging. 如果在Firebase云消息传递上完全连接,我正在寻找一种读取或收听更改的方法。 Notifications are sent to the Android project on firebase, so am supposed to check on the Android application if there are new notifications.
通知会发送到Firebase上的Android项目,因此应该检查Android应用程序中是否有新的通知。
Am I supposed to use the code below? 我应该使用下面的代码吗?
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom())
}
I tried to follow the documentation Firebase cloud messaging . 我试图遵循Firebase云消息传递文档。 But am challenged by checking the new notifications on FCM.
但是通过检查FCM上的新通知受到了挑战。
You can check whether the notification is fired or not : 您可以检查通知是否被触发 :
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.e(TAG, "From: " + remoteMessage.getFrom());
Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());
if (remoteMessage.getNotification() == null)
return;
// Check if message contains a notification payload.
if(remoteMessage.getNotification() != null) {
handleNotification(remoteMessage, remoteMessage.getNotification().getBody(), remoteMessage.getNotification().getTitle());
}
If you mean like list all notifications from Android, you cannot do that I believe. 如果您想列出所有来自Android的通知,我相信您无法做到。 It is the other way around: Firebase tells you when a new notification is available to one particular client via the onMessageReceived method.
这是另一回事:Firebase通过onMessageReceived方法告诉您何时新通知可用于一个特定的客户端。 If you need additional logic you might want to use your backend to store notifications when fired and then the Android side could match the new notification based on it's unique ID with the backend to do further actions ie making sure the user got the notification, statistics etc.
如果您需要其他逻辑,则可能需要在触发时使用后端存储通知,然后Android端可以根据新通知的唯一ID将新通知与后端进行匹配,以执行进一步的操作,即确保用户获得了通知,统计信息等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.