Using the AppMetrica Push SDK with other push services

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

The following steps describe how to configure the application to handle push messages when using multiple push services.

  1. Configuring Firebase Cloud Messaging (FCM)
  2. Configuring Google Cloud Messaging (GCM)

Configuring Firebase Cloud Messaging (FCM)

To configure FCM, follow these steps:

Step 1. Declare additional FirebaseMessagingService

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 processing of push messages

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

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.
    }}

Configuring Google Cloud Messaging (GCM)

To configure GCM, follow these steps:

Step 1. Declare an additional GCMListenerService

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

<service
    android:name=".GCMListenerMasterService"
    android:enabled="true"
    android:exported="false" >
    <intent-filter android:priority="100" >
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    </intent-filter>
</service>
<service android:name="com.yandex.metrica.push.gcm.MetricaGcmListenerService" tools:node="remove" />

Step 2. Add processing of push messages

Declare the derived GCMListenerMasterService class from the base GcmListenerService class for handling push messages:

public class GCMListenerMasterService extends GcmListenerService {
    @Override
    public void onMessageReceived(String from, Bundle data) {

        data.putString("from", from);

        // AppMetrica automatically recognizes its messages and processes them only.
        new MetricaGcmListenerService().processPush(this, data);

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