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