Push Notifications

This guide walks you through setting up the Rover SDK in your app to enable push notifications.


Receive Firebase Push Token

Because Rover is avoiding directly calling the FCM library itself, you’ll need to pass a closure into NotificationsAssembler for requestPushToken to allow it to request the token from Firebase. It was already included in the Rover.initialize(…) example given in Getting Started, but it is repeated here for clarity:

NotificationsAssembler(
    // ...,
    requestPushToken = { tokenFutureCallback ->
        FirebaseInstanceId.getInstance().instanceId.addOnCompleteListener { task ->
            tokenFutureCallback(task.result?.token)
        }
    }
)

Firebase Message Receiver

The FCM library calls your Firebase Message Receiver with the incoming push notifications themselves. They need to be delivered to the Rover SDK so they can be populated into Android’s notification drawer and added to the Rover Notification Center. The FCM library may also call it with a new push token in the event of a remote update to the push token by Google.

Create a Firebase Message Receiver:

import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import io.rover.core.Rover
import io.rover.notifications.pushReceiver

class FirebaseMessageReceiver : FirebaseMessagingService() {
    override fun onMessageReceived(remoteMessage: RemoteMessage) {
        Rover.sharedInstance.resolve(PushReceiverInterface::class.java)?.onMessageReceivedData(
            remoteMessage.data
        )
    }

    override fun onNewToken(newToken: String?) {
        Rover.sharedInstance.resolve(PushReceiverInterface::class.java)?.onTokenRefresh(
            newToken
        )
    }
}

And add it to the application’s manifest:

<service android:name=".FirebaseMessageReceiver" android:exported="true">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
    <intent-filter>
         <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
     </intent-filter>
</service>