Android SDK API Reference
Generated from Dokka/KDoc annotations in hober-android-sdk. The full Dokka HTML site is hosted at https://docs.hober.io/android-sdk/dokka/ and regenerated on every v* release tag.
The Dokka HTML output is produced by
./gradlew :hober-android-sdk:dokkaHtmland uploaded to GCS alongside the Maven Central publish.
Hober
Singleton entry point for the Android SDK. Call Hober.init() once from Application.onCreate() before using any other SDK method.
Hober.init(context, sdkKey, channelId, baseUrl?, httpClient?)
Initializes the SDK. Subsequent calls are a no-op — the SDK logs a warning but does not crash.
Signature
@JvmStatic
@Synchronized
fun init(
context: AppContext,
sdkKey: String,
channelId: String,
baseUrl: String = "https://api.hober.io",
httpClient: HttpClientPort = DefaultHttpClient()
): Unit
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
context | AppContext | Yes | Application context. Use AppContextImpl(this) from your Application. |
sdkKey | String | Yes | Your Hober SDK key, sent as the X-SDK-Key header. |
channelId | String | Yes | Notification channel ID for foreground-service notifications. |
baseUrl | String | No | Override the API base URL (default: https://api.hober.io). |
httpClient | HttpClientPort | No | Override the HTTP client (useful for tests). |
Throws: N/A — double-init is silently ignored with a warning log.
Hober.requestPermission(activity, onResult)
Requests the POST_NOTIFICATIONS runtime permission on Android 13+ (API 33+).
On Android 12 and below, onResult is invoked immediately with true — no dialog is shown and no permission is required.
Signature
@JvmStatic
fun requestPermission(
activity: ActivityHost,
onResult: (Boolean) -> Unit
): Unit
Parameters
| Parameter | Type | Description |
|---|---|---|
activity | ActivityHost | Wraps the calling Android Activity. Use AndroidActivityHost(activity) in production; FakeActivityHost in tests. |
onResult | (Boolean) -> Unit | Callback invoked with true if permission is granted, false if denied. |
Notes:
- Requires
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />inAndroidManifest.xml. - The system dialog is only shown once. If previously denied, the user must re-enable notifications in Settings.
Hober.identifySubscriber(externalId, email?, attributes?, onResult)
Associates the current user with a Hober subscriber record by calling POST /v1/subscribers/upsert.
The call executes on a background thread; results are delivered through onResult (may be called on any thread).
Signature
@JvmStatic
fun identifySubscriber(
externalId: String,
email: String? = null,
attributes: Map<String, Any>? = null,
onResult: (SubscriberResult) -> Unit
): Unit
Parameters
| Parameter | Type | Description |
|---|---|---|
externalId | String | Your application's user identifier. |
email | String? | Optional email address. |
attributes | Map<String, Any>? | Optional attributes. Values may be String, Number, or Boolean. |
onResult | (SubscriberResult) -> Unit | Callback invoked with SubscriberResult.Success or SubscriberResult.Error. |
Throws: IllegalStateException if init has not been called.
Hober.registerDevice(token, onResult)
Registers an FCM device push token with the Hober backend by calling POST /v1/devices.
Duplicate token registration is idempotent — the backend deduplicates.
Signature
@JvmStatic
fun registerDevice(
token: String,
onResult: (DeviceResult) -> Unit
): Unit
Parameters
| Parameter | Type | Description |
|---|---|---|
token | String | The FCM device token from FirebaseMessagingService.onNewToken. |
onResult | (DeviceResult) -> Unit | Callback invoked with DeviceResult.Success or DeviceResult.Error. |
Throws: IllegalStateException if init has not been called.
HoberFirebaseMessagingService
Extend this class to automatically handle FCM token refresh and incoming messages. It calls Hober.registerDevice() inside onNewToken.
Declaration
open class HoberFirebaseMessagingService : FirebaseMessagingService()
Usage
class MyFirebaseService : HoberFirebaseMessagingService()
Register in AndroidManifest.xml:
<service android:name=".MyFirebaseService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Overridable Methods
| Method | Description |
|---|---|
onNewToken(token: String) | Called when FCM issues a new token. Calls Hober.registerDevice(token) automatically. |
onMessageReceived(message: RemoteMessage) | Override to handle foreground messages. |
Types
SubscriberResult
sealed class SubscriberResult {
object Success : SubscriberResult()
data class Error(val message: String) : SubscriberResult()
}
DeviceResult
sealed class DeviceResult {
object Success : DeviceResult()
data class Error(val message: String) : DeviceResult()
}
AppContext
interface AppContext {
val applicationContext: android.content.Context
}
Use AppContextImpl(application) for production.
ActivityHost
interface ActivityHost {
val sdkInt: Int
fun isPermissionGranted(permission: String): Boolean
fun requestPermission(permission: String, onResult: (Boolean) -> Unit)
}
Use AndroidActivityHost(activity) for production; FakeActivityHost for tests.