Android

Quick Start

Install and initialize the Stay22 Android 3.x SDK.

Install the SDK

Add the Maven repository in settings.gradle.kts:

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url = uri("https://raw.githubusercontent.com/Stay22/stay22-android-sdk/main/maven") }
    }
}

Then add the dependency to the app module:

dependencies {
    implementation("com.stay22:sdk:3.1.1")
}

SDK 3.1.1 requires Android 7.0 (API 24) or later. With the standard Android 7.0 certificate store, the SDK cannot currently verify Stay22's server certificate, so account settings and scheduling requests fail. Apps can still build with minSdk 24.

The consent-required setup and persisted pre-initialization choice are available from SDK 1.4.0.

Inside your application element in AndroidManifest.xml:

<meta-data
    android:name="com.stay22.sdk.RequiresConsent"
    android:value="true" />

Call initialization from Application.onCreate(). Register that Application class in your manifest. Save the current consent choice before initialization:

import android.app.Application
import com.stay22.sdk.Stay22

fun startStay22(application: Application, userHasOptedIn: Boolean) {
    Stay22.setEnabled(application, userHasOptedIn)
    Stay22.initialize(application = application, aid = "your-partner-id")
}

When the user changes their choice, call Stay22.setEnabled(application, enabled) again, before submitting a trip.

Ask for notification permission

Stay22.requestNotificationPermission { granted ->
    // Update your app's permission UI.
}

Call from a resumed Activity. The callback reports the user's answer; the no-argument overload returns the state before the prompt finishes. Check the current state with Stay22.hasNotificationPermission(). Android versions before 13 do not need this runtime prompt.

Tell the SDK about the trip

import com.stay22.sdk.NotificationRequest
import com.stay22.sdk.NotificationResult
import com.stay22.sdk.NotificationTiming
import com.stay22.sdk.Stay22
import com.stay22.sdk.TravelContext

fun submitTrip(): NotificationResult {
    val now = System.currentTimeMillis()
    return Stay22.notifications.ensure(
        NotificationRequest(
            trip = TravelContext(address = "Paris, France"),
            timing = NotificationTiming.After(30 * 60 * 1000L),
            expiresAtMs = now + 12 * 60 * 60 * 1000L,
            actionExpiresAtMs = now + 24 * 60 * 60 * 1000L,
        ),
    )
}

The example chooses a 30-minute minimum wait and its own execution and tap deadlines; these are illustrative app choices, not SDK defaults. expiresAtMs limits scheduling, while actionExpiresAtMs limits opening after a tap. If you omit either deadline, the SDK needs a cached account validity policy or rejects the request with expiry_required.

Each request contains the whole trip. Omitted fields do not inherit earlier values. A submitted result acknowledges storage, not that the operating system has queued or shown the notification. Read receipt and timing behavior before deciding how to retry or replace it.

Platform setup notes

The SDK's manifest merges the network permission, notification permission, booking-app visibility declarations and tap-handling Activity into your app. To use your own status-bar icon, add application metadata:

<meta-data
    android:name="com.stay22.sdk.notification_small_icon"
    android:resource="@drawable/ic_stat_notification" />

Check the integration

Follow the test notification instructions. Read what reaches Stay22 before completing your store privacy declarations.

On this page