Android Setup

Installation

The Rover SDK is a collection of Android libraries written in Kotlin. Instead of a single monolithic library, the Rover SDK takes a modular approach, allowing you to include only the functionality relevant to your application. The SDK source code is available on GitHub.


Install the SDK

The first step is to add the library dependencies. We’ll start with a default installation, featuring all of the Rover libraries.

Ensure that you have Rover's maven repository added to the dependencies repositories block of your app-level build.gradle:

dependencies {
    // ...
    repositories {
        // ...
        maven {
            url "https://roverplatform.github.io/rover-maven/maven"
        }
    }
}

Then add the following to your application-level build.gradle file (not the top level build.gradle, but rather your app-level one) in the dependencies block.

dependencies {
    // ...
    implementation "io.rover.sdk:core:4.0.0"
    implementation "io.rover.sdk:notifications:4.0.0"
    implementation "io.rover.sdk:experiences:4.0.0"
    implementation "io.rover.sdk:location:4.0.0"
    implementation "io.rover.sdk:debug:4.0.0"
}

It’s an a-la-carte selection; you can leave off modules (other than the first, core, which is always required) that you don’t need for your product. There are various reasons why you may not want to include all the Rover libraries in your project. For instance, you can save method count and APK size by leaving off Rover libraries that you don't need.


Initialization

In your app’s Application.onCreate method or anywhere else you prefer to put initialization logic (such as a dependency injection framework), call Rover.initialize with the list of Assemblers:

Rover.initialize(
    CoreAssembler(
        accountToken = "YOUR_SDK_TOKEN",
        application = this,
        urlSchemes = listOf("rv-myapp"),
        associatedDomains = listOf("myapp.rover.io")
    ),
    ExperiencesAssembler(),
    NotificationsAssembler(
        applicationContext = this,
        notificationCenterIntent = Intent(context, MyNotificationCenterActivity::class.java),
        smallIconResId = R.mipmap.my_small_icon,
        requestPushToken = { tokenCallback ->
            // this will be discussed later on the "Push Notifications" page.
            FirebaseMessaging.getInstance().token.addOnCompleteListener { task -> 
                if (task.isSuccessful) tokenCallback(task.result) 
            }
        }
    ),
    LocationAssembler(),
    DebugAssembler()
)

Rover.installSaneGlobalHttpCache(application)

Global HTTP Cache Settings

The reasoning for the inclusion of Rover.installSaneGlobalHttpCache() is that in order to keep its footprint small Rover uses Android’s built-in HTTP client, HttpsUrlConnection, and a characteristic of that HTTP client is that its cache must be enabled or disabled globally. Rover requires a working HTTP client cache, and so asks you to invoke this method here to explicitly install a cache to ensure that you are not surprised by Rover changing global configuration. Note that this will have no impact on the other components of your app if you use OkHttp/Retrofit or Volley.

Wherever you put it, you need to be certain that Rover is initialized before Android can dispatch an Intent to the app, such as a push notification or deep link open.

Don’t sweat the parameters for now; they’re in each section of the documentation for each module.

Add the Experience Activity to Manifest

Rover's Experiences feature is typically used in an Activity, and one is bundled with the SDK. Add an entry for it to your manifest:

<activity
    android:name="io.rover.sdk.experiences.ExperienceActivity"
    android:exported="true"
    />

ExperienceActivity Color Theming

Classic Experiences feature the ability to adopt the color scheme of your app for the app bar, using the "Auto-Style" setting. This means you'll need to give the SDK some information about your theme in order for it to adopt it.

You can either use classic Android color values (such as you might resolve from your theme resource XML files), or you might use your Jetpack Compose theme colors.

Provide the appThemeDescription parameter to the ExperienceAssembler() in your Rover initialization lines.

Using Classic Android Color Values

Create a new AppThemeDescription.ThemeColors object with android numeric color values resolved from your theme like this, and provide it to ExperiencesAssembler:

Rover.initialize(
    ...,
    ExperienceAssembler(
    appThemeDescription = AppThemeDescription(
        lightColors = AppThemeDescription.ThemeColors(
            // get your colors from your theme resources like this:
            primary = this.resources.getColor(R.color.colorPrimary, null),
            onPrimary = this.resources.getColor(R.color.colorAccent, null)
        ),
        darkColors = AppThemeDescription.ThemeColors(
            // get your colors from your theme resources like this:
            primary = this.resources.getColor(R.color.colorPrimaryDark, null),
            onPrimary = this.resources.getColor(R.color.colorAccent, null)
        )
    )
)

Using Jetpack Compose Colors

Create a new AppThemeDescription.ThemeColors object with your Jetpack Compose Colors values (as are likely present in your Theme.kt file generated by Android Studio), and provide it to ExperiencesAssembler:

Rover.initialize(
    ...,
    ExperienceAssembler(
        appThemeDescription = AppThemeDescription(
            lightColors = AppThemeDescription.ThemeColors(LightColorPalette),
            darkColors = AppThemeDescription.ThemeColors(DarkColorPalette)
        )
    )
)
Previous
Location