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 hostApplicationinstance.iconRes(required) — Drawable resource ID for the notification small icon. Must be white on a transparent background (24x24 dp).strictProvider(optional) —MobileServiceType.FCMorMobileServiceType.HMS. When set, the SDK uses only that provider and fails viaonFailureif it is not available. Passnullto auto-detect (HMS preferred over FCM).onFailure(optional) — Called if push initialization fails. Receives anException.onTokenReady(optional) — Called when the push token is obtained or refreshed. Receives aToken. Provides a single-call entry point so you do not need to callConnect.push.turnOnPush()andConnect.push.getToken()separately afterConnect.enable().onPermissionResult(optional) — Called after thePOST_NOTIFICATIONSpermission dialog is resolved.true= granted,false= denied. On devices below Android 13 (API 33), always called withtrueimmediately.
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
onTokenReadytoConnectPushConfig. The SDK registers the device and delivers the token via the callback afterConnect.enable(). - Manual — omit
onTokenReadyand callConnect.push.turnOnPush()explicitly when you want to register. UseturnOffPush(),getToken(), anddeleteToken()to manage the token lifecycle — for example, to support an opt-in flow or user-controlled push settings.
Token management (manual mode)
| Method | Description |
|---|---|
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
| Method | Description |
|---|---|
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
Connect.push.isInitializedReturns true if push has been successfully initialized.
Connect.push.isInitialized(): BooleanConnect.push.requestNotificationPermission
Connect.push.requestNotificationPermissionRequests 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 foregroundComponentActivity. The SDK unregisters the launcher automatically on activity destruction.onResult(optional) — One-shot callback invoked after the dialog is resolved.true= granted,false= denied. OverridesConnectPushConfig.onPermissionResultfor this request.
Connect.push.isPushAccepted
Connect.push.isPushAcceptedReturns the notification permission state.
Connect.push.isPushAccepted(context: Context): Boolean?Returns three possible values:
| Return value | Meaning |
|---|---|
true | Permission granted |
false | Permission denied |
null | Dialog 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
Connect.push.getPushPermissionStateReturns the three-state notification permission status.
Connect.push.getPushPermissionState(context: Context): PushPermissionStateUnlike isPushAccepted(), returns a typed PushPermissionState enum: GRANTED, DENIED, or NOT_DETERMINED. Always returns GRANTED on devices below Android 13 (API 33).
Connect.push.getToken
Connect.push.getTokenRetrieves 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
Connect.push.deleteTokenDeletes the current push token from the provider.
Connect.push.deleteToken(): Work<Unit>Connect.push.turnOnPush
Connect.push.turnOnPushOpts the device into push notifications.
Connect.push.turnOnPush(): Work<Unit>Connect.push.turnOffPush
Connect.push.turnOffPushOpts the device out of push notifications.
Connect.push.turnOffPush(): Work<Unit>Connect.push.getAAID
Connect.push.getAAIDRetrieves the Huawei Anonymous Application Identifier (AAID).
Connect.push.getAAID(): Work<AAIDResultWrapper>Connect.push.setImageLoaderType
Connect.push.setImageLoaderTypeSets the image loader used for rich media notifications.
Connect.push.setImageLoaderType(type: ImageLoaderType)| Value | Description |
|---|---|
ImageLoaderType.NATIVE | Default. No extra dependency required. |
ImageLoaderType.GLIDE | Uses Glide. Requires the Glide library in your dependencies. |
Connect.push.getImageLoaderType
Connect.push.getImageLoaderTypeReturns the current image loader type.
Connect.push.getImageLoaderType(): ImageLoaderTypeMobileServiceType
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
)| Field | Description |
|---|---|
provider | Provider.Google or Provider.Huawei. |
token | The raw push token string. |
isNewToken | true if this is a newly generated token. |
Updated 2 days ago
