Multiple Push SDKs
This topic provides steps for configuring your mobile app to identify and display push notifications from Responsys when using multiple push SDKs in the same app. Before proceeding, ensure you have followed through the Step-by-Step guide and any other feature-specific guides.
Overview
The Responsys Mobile SDK supports co-existing with other push provider SDKs within the same app. While we do not certify this behavior with other providers individually, as long as the other SDKs follow the standard Android App Development Guidelines, there should be no issues with such integrations.
Let's get started!
Step 1: Implement Custom Message Handler Service
Since there are multiple SDKs trying to access the device tokens and push notifications, you will need to implement your own FirebaseMessagingService
class, which receives the device token/message and will forward it to the correct SDK.
[1.1] Create custom Service
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onNewToken(String s) {
super.onNewToken(s);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
}
}
class MyFirebaseMessagingService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
super.onNewToken(token)
}
override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
}
}
[1.2] Declare Service in Manifest
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Step 2: Share Device Token
When any of the SDKs in your app request a device token, the onNewToken()
of your custom Service class is called with the new token. You must share this device token with the Responsys Mobile SDK.
@Override
public void onNewToken(String token) {
super.onNewToken(token);
// Set the device token in Responsys Mobile SDK
PushIOManager.getInstance(getApplicationContext()).setDeviceToken(token);
// Optionally, also share with other SDKs
}
override fun onNewToken(token: String) {
super.onNewToken(token)
// Set the device token in Responsys Mobile SDK
PushIOManager.getInstance(getApplicationContext()).setDeviceToken(token);
// Optionally, also share with other SDKs
}
Step 3: Handle Incoming Push Notifications
When a new push notification is received by the device, the `onMessageReceived()
of your custom Service class is called. Here, it is important to identify the source of the push notification and direct the payload to the correct SDK accordingly.
The Responsys Mobile SDK v6.42 and later provide convenient methods to identify if the push notification originated from Responsys, and then forwards the push notification to the Responsys Mobile SDK.
boolean isResponsysPush ( RemoteMessage remoteMessage )
void handleMessage ( RemoteMessage remoteMessage )
The following sample demonstrates the usage:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
PushIOManager pushIOManager = PushIOManager.getInstance(getApplicationContext());
if (pushIOManager.isResponsysPush(remoteMessage)) {
pushIOManager.handleMessage(remoteMessage);
} else {
// Not a Responsys push notification, handle it appropriately
}
}
override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
val pushIOManager = PushIOManager.getInstance(applicationContext)
if (pushIOManager.isResponsysPush(remoteMessage)) {
pushIOManager.handleMessage(remoteMessage)
} else {
// Not a Responsys push notification, handle it appropriately
}
}