Using with other push services

You can use AppMetrica Push SDK and other push services at the same time. To do this, you need to create a FCM or HMS service that will redirect messages between integrated SDKs.

  1. Using with other Firebase push services
  2. Using with other HMS push services

Using with other Firebase push services

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"/>
Copied to clipboard

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) {
        super.onMessageReceived(message);
        if (MetricaMessagingService.isNotificationRelatedToSDK(message) {
            new MetricaMessagingService().processPush(this, message);
            return;
        }
        
        // Implement the logic for sending messages to other SDKs or handle own pushes.
    }
}
Copied to clipboard

Step 3. Add push token processing

Add push token processing to the FirebaseMessagingMasterService class code:

public class FirebaseMessagingMasterService extends FirebaseMessagingService {
    ...

    @Override
    public void onNewToken(@NonNull String token) {
        super.onNewToken(token);
        new MetricaMessagingService().processToken(this, token);

        // Implement the logic for sending tokens to other SDKs.
    }
}
Copied to clipboard

Using with other HMS push services

Step 1. Make changes in AndroidManifest.xml

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

<service
    android:name=".HmsMessagingMasterService"
    android:exported="true"
    android:permission="${applicationId}.permission.PROCESS_PUSH_MSG">
    <intent-filter android:priority="100">
        <action android:name="com.huawei.push.action.MESSAGING_EVENT" />
    </intent-filter>
</service>
<service android:name="com.yandex.appmetrica.push.hms.MetricaHmsMessagingService" tools:node="remove"/>
Copied to clipboard

Step 2. Add push notifications handling

Declare the derived HmsMessagingMasterService class from the base HmsMessageService class for handling push notifications:

public class HmsMessagingMasterService extends HmsMessageService {
    @Override
    public void onMessageReceived(RemoteMessage message) {
        super.onMessageReceived(message);
        if (MetricaHmsMessagingService.isNotificationRelatedToSDK(message) {
            new MetricaHmsMessagingService().processPush(this, message);
            return;
        }
        
        // Implement the logic for sending messages to other SDKs or handle own pushes.
    }
}
Copied to clipboard

Step 3. Add push token processing

Add push token processing to the HmsMessagingMasterService class code:

public class HmsMessagingMasterService extends HmsMessageService {
    ...

    @Override
    public void onNewToken(@Nullable String token) {
        super.onNewToken(token);
        new MetricaHmsMessagingService().processToken(this, token);

        // Implement the logic for sending tokens to other SDKs.
    }
}
Copied to clipboard

If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.