简体   繁体   English

如何在应用程序运行时获取或检测 FCM 通知?

[英]How can i get or detect FCM notification while app running?

I am trying to show in App notification to my current using user.我试图在应用程序通知中显示给我当前使用的用户。 But, FCM only show to foreground and background users.但是,FCM 只显示给前台和后台用户。 How can i do it?我该怎么做?

You can create a service that will receive all FCM messages and then you can react on the received messages accordingly to show a notification.您可以创建一个服务来接收所有 FCM 消息,然后您可以对收到的消息做出相应的反应以显示通知。

https://firebase.google.com/docs/cloud-messaging/android/receive https://firebase.google.com/docs/cloud-messaging/android/receive

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Map<String, String> message = remoteMessage.getData();
        // do something once message is received
        }
}

In your manifest:在您的清单中:

<service
    android:name=".MyFirebaseMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序未运行时如何发送 fcm 通知 - How to send fcm notification when app is not running 当 android 应用程序处于终止状态时,如何从推送通知(使用 FCM)中获取“数据有效负载”? - How can I get “data payload” from push notification (using FCM) when android app is in killed state? 当我的应用程序运行时,如何在不单击通知的情况下使用GCM通知内容更新当前活动? - While my app is running, how can I update the current activity with the contents a GCM notification, without clicking on the notification? 应用程序运行android时,如何在通知区域放置通知图标? - How can I put notification icon in notification area while app is running android? 如何检测令牌是否已过期或未在应用服务器上注册firebase FCM通知? - How to detect if token is expired or not registred firebase FCM notification on app server? 我如何仅在应用程序终止时接收 FCM 通知,如果应用程序在后台运行则不接收它 - How I can receive FCM notification only when app is terminated and doesn't receive it if app is working in background 我的应用未运行时,如何发送类似Facebook的推送通知(背景/前景) - how can i send push notification like facebook while my app is not running(background/foreground) 在运行和终止时处理FCM通知 - Handling FCM Notification while running and killed 当应用收到fcm通知时,如何显示自定义上/下视图 - How can I show a custom top/down view when app received fcm notification 如何设置应用服务器以通过FCM将设备发送到设备通知? - How can I set up an app server to send device to device notification via FCM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM