Skip to content

How to integrate the Infobip Mobile Messaging SDK with another push notifications provider

Ivan Bilobrk edited this page Apr 30, 2025 · 2 revisions

If you plan to integrate your mobile application with multiple push notification providers, or maybe you use FCM/APNS to process push from a native backend and don't want to migrate the entire codebase to use with Infobip (for example there's still some use cases where you want to send notifications directly to Firebase/APNS), then you will need to follow this guide.

Android

For Android, you will need to implement a custom FirebaseMessagingService.

How to implement a custom FirebaseMessagingService?

The FirebaseMessagingService is a service which acts as an entry point for handling messages from FCM. Extending this service is required for you to have one place in your app to handle all Firebase messages and to act as a proxy object between multiple push notification providers. In this guide, we are interested in 2 methods: onMessageReceived and onNewToken, which we will later override. The onMessageReceived method is called when a message is received from the FCM and the onNewToken method is called when a new token is generated by the FCM. In order to handle new messages and tokens and to make sure that a custom implementation of these methods will be used, you have to add the following to your app AndroidManifest.xml under the <application> tag:

<application>
    ...
    <service
        android:name=".YourFirebaseMessagingServiceName"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    ...
</application>

An Android application is supposed to have only one service registered for a com.google.firebase.MESSAGING_EVENT action. If there are multiple services registered for a com.google.firebase.MESSAGING_EVENT action, only the first one declared in your app's AndroidManifest.xml will be used. To make sure that your custom service is the one that has this action and to not rely on the order specified in the manifest, add the following to your app's AndroidManifest.xml under the <application> tag for all services that extend the FirebaseMessagingService:

<application>
    ...
    <service
            android:name=".FirstPushProviderFirebaseMessagingServiceName"
            android:exported="false">
        <intent-filter tools:node="remove">
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    <service
            android:name=".SecondPushProviderFirebaseMessagingServiceName"
            android:exported="false">
        <intent-filter tools:node="remove">
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    ...
</application>

Before implementing a custom FirebaseMessagingService, ensure you are familiar with the methods provided by other push notification providers for handling incoming messages and token updates. Create a file named YourFirebaseMessagingServiceName.kt/YourFirebaseMessagingServiceName.java in your app's source set (e.g., android/app/src/main/kotlin(java)/YourFirebaseMessagingServiceName.kt(java)). To be able to reference Infobip Mobile Messaging SDK and FCM methods in your service, in app/build.gradle of your Android project add the following to dependencies section:

dependencies {
...
    implementation ('com.infobip:infobip-mobile-messaging-android-sdk:sdkVersion@aar') {
        transitive = true
    }
...
}

Here is an example of how to implement a custom FirebaseMessagingService:

import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage

import org.infobip.mobile.messaging.cloud.firebase.MobileMessagingFirebaseService
import com.infobip.webrtc.ui.service.InfobipRtcUiFirebaseService

class YourFirebaseMessagingServiceName : FirebaseMessagingService() {
    override fun onMessageReceived(remoteMessage: RemoteMessage) {
        if (MobileMessagingFirebaseService.onMessageReceived(this, remoteMessage)) {
            return
        }

        //NOTE: needed only if you use the Infobip RTC
        if (InfobipRtcUiFirebaseService.onMessageReceived(this, remoteMessage)) {
            return
        }

        // process non-Infobip notifications here or pass them to another push notification provider
        // TODO your code
    }

    override fun onNewToken(token: String) {
        MobileMessagingFirebaseService.onNewToken(this, token)

        //NOTE: needed only if you use the Infobip RTC
        InfobipRtcUiFirebaseService.onNewToken(this, token)

        // process Firebase token here or pass it to another push notification provider
        // TODO your code
    }
}
expand to see Java code

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

import org.infobip.mobile.messaging.cloud.firebase.MobileMessagingFirebaseService;
import com.infobip.webrtc.ui.service.InfobipRtcUiFirebaseService;

public class YourFirebaseMessagingServiceName extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        if (MobileMessagingFirebaseService.onMessageReceived(this, remoteMessage)) {
            return;
        }

        //NOTE: needed only if you use the Infobip RTC
        if (InfobipRtcUiFirebaseService.onMessageReceived(this, remoteMessage)) {
            return;
        }

        // process non-Infobip notifications here or pass them to another push notification provider
        // TODO your code
    }

    @Override
    public void onNewToken(String token) {
        MobileMessagingFirebaseService.onNewToken(this, token);

        //NOTE: needed only if you use the Infobip RTC
        InfobipRtcUiFirebaseService.onNewToken(this, token);

        // process Firebase token here or pass it to another push notification provider
        // TODO your code
    }
}

More information about the Infobip RTC and the Firebase Messaging Service delegation can be found here.

Notice

Other push notification providers might use legacy methods to handle new FCM messages by implementing a BroadcastReceiver instead of a FirebaseMessagingService. However, they may still rely on FirebaseMessagingService for handling new tokens, so it remains important to implement a custom FirebaseMessagingService.

Notice

Without a properly implemented custom FirebaseMessagingService, Infobip's SDK will not be able to receive notifications and token updates. Since having a fresh FCM token is necessary not only for Infobip's SDK but also for other push notification providers, it is important to handle new tokens correctly in a custom FirebaseMessagingService. There are cases — such as depersonalization and repersonalization — where Infobip's SDK triggers a token update from FCM. If the custom FirebaseMessagingService does not propagate this new token properly to the other push notification providers, they might not be able to send notifications or display them correctly on the device.

How to resolve possible version conflicts of firebase-messaging and kotlin-stdlib-jdk8 libraries?

If you encounter version conflicts of firebase-messaging library, you can resolve it by adding the following to your app's build.gradle file:

dependencies {
...
   configurations.configureEach {
       resolutionStrategy {
           force "com.google.firebase:firebase-messaging:versionNumber"
       }
   }
...
}

If you encounter version conflicts of kotlin-stdlib-jdk8 library, you can resolve it by adding the following to your app's build.gradle file:

dependencies {
...
   configurations.configureEach {
       resolutionStrategy {
           force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:versionNumber"
       }
   }
...
}

Push Notification Permission Handling

Infobip Mobile Messaging SDK won't automatically ask for push notification permission on Android 13 and above. If you want to use Infobip Mobile Messaging SDK to ask for push notification permission, you can check this guide.

Clone this wiki locally