Connect Android SDK: push notifications

The page describes the classes and methods for push notifications in the Connect Android SDK.

Platform: Android 8-16
Languages: Kotlin and Java
Declared in: connect-push, connect-push-fcm, connect-push-hms


ConnectPushConfig

Configuration object passed to Connect.enable() or ConnectWrapper to enable push notifications.

class ConnectPushConfig(
    val application: Application,
    val iconRes: Int,
    val strictProvider: MobileServiceType? = null,
    val onFailure: (Exception) -> Unit = {},
    val onTokenReady: (Token) -> Unit = {},
    val onPermissionResult: ((Boolean) -> Unit)? = null
)

Parameters:

  • application (required) — The host Application instance.
  • iconRes (required) — Drawable resource ID for the notification small icon. Must be white on a transparent background (24x24 dp).
  • strictProvider (optional) — MobileServiceType.FCM or MobileServiceType.HMS. When set, the SDK uses only that provider and fails via onFailure if it is not available. Pass null to auto-detect (HMS preferred over FCM).
  • onFailure (optional) — Called if push initialization fails. Receives an Exception.
  • onTokenReady (optional) — Called when the push token is obtained or refreshed. Receives a Token. Provides a single-call entry point so you do not need to call Connect.push.turnOnPush() and Connect.push.getToken() separately after Connect.enable().
  • onPermissionResult (optional) — Called after the POST_NOTIFICATIONS permission dialog is resolved. true = granted, false = denied. On devices below Android 13 (API 33), always called with true immediately.

Java note

Kotlin lambda parameters (onFailure, onTokenReady, onPermissionResult) map to SAM interfaces in Java. Pass a lambda expression or anonymous class:

new ConnectPushConfig(
    application,
    R.drawable.ic_notification,
    null,
    exception -> { /* handle failure */ },
    token -> { /* handle token */ },
    granted -> { /* handle permission result */ }
);

PushApi

The push notification interface. Access via Connect.push after calling Connect.enable() with a ConnectPushConfig.

The SDK supports two token management modes:

  • Automatic (recommended) — pass onTokenReady to ConnectPushConfig. The SDK registers the device and delivers the token via the callback after Connect.enable().
  • Manual — omit onTokenReady and call Connect.push.turnOnPush() explicitly when you want to register. Use turnOffPush(), getToken(), and deleteToken() to manage the token lifecycle — for example, to support an opt-in flow or user-controlled push settings.

Token management (manual mode)

MethodDescription
turnOnPush()Registers the device and obtains a token.
turnOffPush()Opts the device out of push notifications.
getToken()Retrieves the current token.
deleteToken()Removes the token from the provider.

Permission

MethodDescription
requestNotificationPermission()Requests the POST_NOTIFICATIONS permission on Android 13+.
isPushAccepted()Returns the permission state as Boolean?true, false, or null (not yet shown).
getPushPermissionState()Returns the permission state as a typed PushPermissionState enum.

Connect.push.isInitialized

Returns true if push has been successfully initialized.

Connect.push.isInitialized(): Boolean

Connect.push.requestNotificationPermission

Requests the POST_NOTIFICATIONS permission on Android 13 (API 33) and later.

Connect.push.requestNotificationPermission(
    activity: ComponentActivity,
    onResult: ((Boolean) -> Unit)? = null
)

The SDK fully manages the permission flow. Safe to call unconditionally — no-ops on pre-Android 13 devices and skips the dialog if permission is already granted.

Parameters:

  • activity (required) — The foreground ComponentActivity. The SDK unregisters the launcher automatically on activity destruction.
  • onResult (optional) — One-shot callback invoked after the dialog is resolved. true = granted, false = denied. Overrides ConnectPushConfig.onPermissionResult for this request.

Connect.push.isPushAccepted

Returns the notification permission state.

Connect.push.isPushAccepted(context: Context): Boolean?

Returns three possible values:

Return valueMeaning
truePermission granted
falsePermission denied
nullDialog not yet shown

Always returns true on devices below Android 13 (API 33).

when (Connect.push.isPushAccepted(context)) {
    true  -> { /* permission granted */ }
    false -> { /* permission denied  */ }
    null  -> { /* dialog not yet shown */ }
}

Connect.push.getPushPermissionState

Returns the three-state notification permission status.

Connect.push.getPushPermissionState(context: Context): PushPermissionState

Unlike isPushAccepted(), returns a typed PushPermissionState enum: GRANTED, DENIED, or NOT_DETERMINED. Always returns GRANTED on devices below Android 13 (API 33).


Connect.push.getToken

Retrieves the current push token.

Connect.push.getToken(): Work<Token>

Returns a Work<Token>. Use addOnSuccessListener and addOnFailureListener to handle the result:

Connect.push.getToken()
    .addOnSuccessListener { token ->
        // token.token: String
        // token.provider: Provider (Provider.Google or Provider.Huawei)
        // token.isNewToken: Boolean
    }
    .addOnFailureListener { error ->
        // handle error
    }

Notes

  • Callbacks are called on a background thread. Dispatch to the main thread if you need to update UI.
  • Java — use anonymous classes or method references instead of Kotlin lambdas.
ConnectKt.getPush(Connect.INSTANCE).getToken()
    .addOnSuccessListener(token -> {
        String rawToken = token.getToken();
        Provider provider = token.getProvider();
    })
    .addOnFailureListener(error -> {
        // handle error
    });

Connect.push.deleteToken

Deletes the current push token from the provider.

Connect.push.deleteToken(): Work<Unit>

Connect.push.turnOnPush

Opts the device into push notifications.

Connect.push.turnOnPush(): Work<Unit>

Connect.push.turnOffPush

Opts the device out of push notifications.

Connect.push.turnOffPush(): Work<Unit>

Connect.push.getAAID

Retrieves the Huawei Anonymous Application Identifier (AAID).

Connect.push.getAAID(): Work<AAIDResultWrapper>

Connect.push.setImageLoaderType

Sets the image loader used for rich media notifications.

Connect.push.setImageLoaderType(type: ImageLoaderType)
ValueDescription
ImageLoaderType.NATIVEDefault. No extra dependency required.
ImageLoaderType.GLIDEUses Glide. Requires the Glide library in your dependencies.

Connect.push.getImageLoaderType

Returns the current image loader type.

Connect.push.getImageLoaderType(): ImageLoaderType

MobileServiceType

enum class MobileServiceType {
    FCM,   // Firebase Cloud Messaging (Google)
    HMS    // Huawei Mobile Services
}

Relevant only when using the :connect-push artifact, which bundles both FCM and HMS and auto-detects the available provider. Pass to ConnectPushConfig.strictProvider to pin a specific provider and disable auto-detection. If you use :connect-push-fcm or :connect-push-hms directly, the provider is implicit and strictProvider has no effect.


Token

data class Token(
    val provider: Provider,
    val token: String,
    val isNewToken: Boolean
)
FieldDescription
providerProvider.Google or Provider.Huawei.
tokenThe raw push token string.
isNewTokentrue if this is a newly generated token.