简体   繁体   English

在Firebase Cloud Messaging上检查新通知。 (FCM)

[英]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.

相关问题 FCM Cloud Messaging 与 Notifications 和 Message 的区别 - FCM Cloud Messaging difference from Notifications and Message 是否可以在没有 Firebase Cloud Messaging (FCM) 的情况下向所有安装了我的应用程序的设备发送推送通知? - is it possible to make push notifications to all devices which had installed my application without Firebase Cloud Messaging (FCM)? addCompleteListener()尚未解决-Firebase Cloud Messaging(FCM) - addCompleteListener() is not being resolved - Firebase Cloud Messaging (FCM) MismatchSenderId错误Firebase云消息传递(FCM) - MismatchSenderId error Firebase Cloud Messaging (FCM) Firebase Cloud Messaging(FCM)无法获取数据 - Firebase Cloud Messaging (FCM) not getting data 如何向FCM(Firebase云消息传递)令牌的特定用户发送消息? - How to send a message to a specific user of an FCM (Firebase Cloud Messaging) token? 如何使用Firebase Cloud Messaging根据Firebase数据发送通知 - How to send notifications depending on the Firebase data using Firebase Cloud Messaging Firebase Cloud Messaging生成新的发件人ID - Firebase Cloud Messaging generate a new Sender ID 调用“ https://fcm.googleapis.com/fcm/send”时,Firebase云消息传递出现内部服务器错误 - Firebase cloud messaging getting internal server error when calling “https://fcm.googleapis.com/fcm/send” 使用XMPP服务器和Google云消息传递(或更新的Firebase云消息传递)进行推送通知的Android应用程序App - Chat App for Android using a XMPP Server and Google Cloud Messaging (or the newer Firebase Cloud Messaging) for Push Notifications
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM