How do I handle multiple push providers on Android?


In our integration docs we show the easiest way to integrate push notifications with Swrve. This assumes that Swrve is the only push provider. This method uses the default SwrveFirebaseMessagingService to handle processing of push notifications and updating push tokens in Swrve. 

If you have multiple push providers you will need create your own Messaging Service to handle push notifications. You will need to pass new tokens to Swrve and make sure Swrve is set to handle incoming notifications. 

Here is an example project in github showing exactly how you should do it:

Instead of pointing to the default SwrveFirebaseMessagingService you point to your own Messaging Service in the AndroidManifest

In the example project we call it "MyFirebaseMessagingService". 
Here you override two methods: 

onNewToken() -

This is called when a new token is generated. Here you need to pass the token to Swrve by calling:


onMessageReceived() - 

This is called when a notification is received on the device. Here you need to pass the notification to the Swrve SDK by calling:

if (!SwrvePushServiceDefault.handle(this, remoteMessage.getData())) {
// Execute code for other push provider

Swrve will only handle the push if it came from Swrve. If not you can execute your own code inside the if statement to handle it yourself. 

Have more questions? Submit a request


Powered by Zendesk