ConnectivityMonitor

Tells whether the device can reach the internet.

Create one monitor per process (keep it in DI or a singleton) with the platform factory: ConnectivityMonitor(context) { ... } on Android, ConnectivityMonitor { ... } elsewhere. Monitoring runs only while something collects isConnected, status or reconnected, and stops stopTimeout after the last collector leaves.

Properties

Link copied to clipboard
abstract val isConnected: StateFlow<Boolean>

true = internet reachable under the configured policy. Hot, conflated, replays the latest value, and never emits the same value twice in a row. Only ConnectivityStatus.Disconnected reads as false.

Link copied to clipboard
abstract val reconnected: Flow<Unit>

One event per offline → online transition (after debounce), per ReconnectedPolicy. Not replayed.

Link copied to clipboard
abstract val status: StateFlow<ConnectivityStatus>

Richer state: transport, metered, constrained, disconnect reason.

Functions

Link copied to clipboard
abstract override fun close()

Stops monitoring for good and releases platform resources. Hint calls become no-ops.

Link copied to clipboard

Calls onChange with every ConnectivityMonitor.isConnected value on the main thread (or Dispatchers.Default where no main dispatcher exists). For Swift and for code without coroutines.

Link copied to clipboard
abstract fun reportReachable()

A response arrived from the network (any HTTP status). Cheap, thread-safe, never blocks. Ignored while nobody collects, and on Android/iOS unless HintConfig.applyOnNativePlatforms.

Link copied to clipboard
abstract fun requestRecheck()

A request failed with an I/O error. Cheap, thread-safe, never blocks. Ignored while nobody collects, and on Android/iOS unless HintConfig.applyOnNativePlatforms.