[英]How can i get or detect FCM notification while app running?
我試圖在應用程序通知中顯示給我當前使用的用戶。 但是,FCM 只顯示給前台和后台用戶。 我該怎么做?
您可以創建一個服務來接收所有 FCM 消息,然后您可以對收到的消息做出相應的反應以顯示通知。
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
}
}
在您的清單中:
<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.