Android Setup

Push Notifications

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

Sane Defaults

We have designed the SDK to afford implementers with a high degree of control and a minimum of magic. As such, there will be a little bit of boilerplate required below, but this approach will make it easier for you to debug problems and manage whatever unusual integration situations might arise in your app, which is particularly handy when dealing with Google libraries such as FCM.


Receive Firebase Push Token

Because the Rover SDK 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 Installation and Initialization, but it is repeated here for clarity:

NotificationsAssembler(
    // ...,
    requestPushToken = { tokenCallback ->
        FirebaseMessaging.getInstance().token.addOnCompleteListener { task -> 
            if (task.isSuccessful) tokenCallback(task.result) 
        }
    }
)

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.sdk.core.Rover
import io.rover.sdk.notifications.PushReceiverInterface

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

    override fun onNewToken(newToken: String) {
        Rover.shared?.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>

Receiving other kinds of pushes

That in the event that you already have Firebase Cloud Messaging configured in your application for receiving non-Rover pushes you can merge the logic above (that, as you can see, is calling methods on Rover's PushReceiverInterface) into your existing implementations of the token and message receiver methods.

Requesting Permission

Since Android 13 and later, Android devices now have an opt-in (vs allow-by-default) permission for delivering pushes to a user. This means that your app will need to request the user's permission to send notifications to their device before Rover notifications will arrive.

You should prompt for this permission where appropriate in your app's user flow.

See the Android documentation for more information on requesting permissions: Notification runtime permission.

Previous
FCM Setup