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.pushReceiver
class FirebaseMessageReceiver : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
if (Rover.shared.pushReceiver.onMessageReceivedData(remoteMessage.data)) return
// non-Rover push received: your own handling
}
override fun onNewToken(newToken: String) {
Rover.shared.pushReceiver.onTokenRefresh(newToken)
}
}
Rover.shared is not nullable, and accessing it before Rover.initialize(…) has run throws.
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
If you already have Firebase Cloud Messaging configured in your application for receiving non-Rover pushes, merge the calls above into your existing token and message receiver methods, and use the return value to decide whether to carry on with your own handling:
override fun onMessageReceived(remoteMessage: RemoteMessage) {
if (Rover.shared.pushReceiver.onMessageReceivedData(remoteMessage.data)) return
// Not a Rover push. Your existing handling goes here.
myOwnPushHandler.handle(remoteMessage)
}
Upgrading from an earlier SDK
The return value is new in 4.16.0, and it is additive: an existing receiver that ignores it still compiles in both Kotlin and Java, and there is no @CheckResult, so rebuilding against 4.16.0 is the whole upgrade.
Two cases do need attention. If you implement PushReceiverInterface yourself rather than using the one Rover provides, your onMessageReceivedData and onMessageReceivedDataAsBundle overrides need the Boolean return type added. And because the method descriptors change from void to boolean, any caller that is not recompiled against 4.16.0, a wrapper library shipped as a prebuilt aar say, needs a rebuild.
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.