Skip to Content
PlatformsAndroidAPI Reference

API Reference

Source: apps/android-sdk/onesygnal/src/main/kotlin/io/onesygnal/sdk/api/OneSygnal.kt. Everything below is a member of the OneSygnal object (a singleton — there’s no factory/constructor).

Callback-based methods

MethodSignatureNotes
initialize(context: Context, completion: ((Boolean) -> Unit)? = null)Completion fires once config/user/surveys are fully fetched and settled, with true; or as soon as possible with false if init couldn’t proceed (e.g. no resolvable API key). Calling it again while already initialized invokes the completion with true immediately and does nothing else.
track(eventName: String, properties: Map<String, Any?> = emptyMap()): BooleanSynchronous, no completion — returns false if not initialized or surveys are disabled, otherwise the result of EventTracker.track(). No I/O happens inline; the event is queued and flushed on EventTracker’s own internal timer.
identify(userId: String, attributes: Map<String, Any?>? = null, completion: ((Boolean) -> Unit)? = null)Completion resolves false immediately if not yet initialized. On success, re-fetches surveys if the last fetch was more than 60s ago.
logout(completion: (() -> Unit)? = null)No-op with an immediate completion call if not initialized.
reset(completion: (() -> Unit)? = null)Clears the identified user, mints a new anonymous ID, re-fetches surveys. No-op if not initialized.
setApiKey(apiKey: String)Override for the manifest-read API key. Must be called before initialize().
setLocale(locale: String)Live-reactive if called after initialize() — see Configuration.
setSurveysEnabled(enabled: Boolean)In-memory flag, works whether or not initialized.
areSurveysEnabled(): BooleanDefault true.
isInitialized(): Boolean
on(event: String, callback: (Any?) -> Unit): RegistrationSee Events. Always returns a Registration synchronously — no “not ready yet” case like Web’s loader.
shutdown(completion: (() -> Unit)? = null)Flushes pending events, tears down listeners/timers, sets initialized = false. No-op if not initialized.

flush is absent

There’s no public manual-flush method on Android. EventTracker and ResponseFlusher each run their own internal periodic timer (started inside backgroundInit()), but neither exposes a hook for a caller to trigger an early flush — Web’s flush() has no Android equivalent.

There’s no off

Unlike Web, Android has no off(event, callback). The only way to unsubscribe is the Registration returned by on() — call .cancel() on it.

Suspend-function equivalents

Named with an Await suffix, not the same name as an overload — suspend fun identify(...) alongside the callback-based fun identify(...) (which also has default parameters) is an ambiguous overload in Kotlin, so the suspend variants get distinct names instead. This is different from iOS, which can use same-name async overloads because Swift disambiguates by call-site shape, not name alone — a language constraint, not an inconsistency.

MethodSignature
initializeAwaitsuspend (context: Context): Boolean
identifyAwaitsuspend (userId: String, attributes: Map<String, Any?>? = null): Boolean
logoutAwaitsuspend (): Unit
resetAwaitsuspend (): Unit
shutdownAwaitsuspend (): Unit

There’s no trackAwaittrack() is already synchronous (no I/O happens inline), so there’s nothing to await.

Registration

fun interface Registration { fun cancel() }

Returned by on(). Call .cancel() to stop receiving that event.

Not public

  • setSdkWrapper(library: String, version: String) — exists on the object but isn’t part of the supported public API for native-app integrators. It’s used internally by wrapper SDKs (e.g. the Flutter bridge) to attribute events to the wrapper rather than the raw Android SDK, and must be called before initialize().
  • emit(event: String, data: Any? = null) — marked internal, not private, only so the SDK’s own test suite can exercise on()/Registration without a real Context. Not accessible outside the SDK module.

See Platform Parity for what exists on every platform.