Pyae Hein
Pyae Hein

Reputation: 105

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. How can i do it?

Upvotes: 1

Views: 551

Answers (1)

Riley MacDonald
Riley MacDonald

Reputation: 463

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.

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>

Upvotes: 1

Related Questions