Using the AppMetrica Push SDK with Firebase Cloud Messaging

You can use the AppMetrica Push SDK with Firebase Cloud Messaging (FCM) at the same time. To do this, you need to create the FCM service that will redirect messages between integrated SDKs.

The section below describes the steps for setting up FCM:

Step 1. Make changes in AndroidManifest.xml

Make changes in the application element in the AndroidManifest.xml file:

<service android:name=".FirebaseMessagingMasterService"
         android:enabled="true"
         android:exported="false">
    <intent-filter android:priority="100">
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>
<service android:name="com.yandex.metrica.push.firebase.MetricaMessagingService" tools:node="remove"/>

Step 2. Add push notifications handling

Declare the derived FirebaseMessagingMasterService class from the base FirebaseMessagingService class for handling push notifications:

public class FirebaseMessagingMasterService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage message) {
        // AppMetrica automatically recognizes its messages and processes them only.
        new MetricaMessagingService().processPush(this, message);

        // Implement the logic for sending messages to other SDKs.
    }
}