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.
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
class FirebaseMessagingMasterService : FirebaseMessagingService() { override fun onMessageReceived(message: RemoteMessage) { super.onMessageReceived(message) if (MetricaMessagingService.isNotificationRelatedToSDK(message) { 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
class FirebaseMessagingMasterService : FirebaseMessagingService() { ... override fun onNewToken(token: String) { super.onNewToken(token); 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
class HmsMessagingMasterService : HmsMessageService() { override fun onMessageReceived(message: RemoteMessage) { super.onMessageReceived(message) if (MetricaHmsMessagingService.isNotificationRelatedToSDK(message) { 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
class HmsMessagingMasterService : HmsMessageService() { ... override fun onNewToken(token: String?) { super.onNewToken(token); MetricaHmsMessagingService().processToken(this, token) // Implement the logic for sending tokens to other SDKs. } }
Copied to clipboard