ConnectivityHelper
Centralized network connectivity helper for Android.
This utility provides synchronous checks and reactive flows for monitoring internet availability and transport types (Wifi, Cellular, etc.).
Requires permission: ACCESS_NETWORK_STATE
Example usage:
val connectivityHelper = ConnectivityHelper(context)
// Synchronous check
if (connectivityHelper.isOnline()) {
refreshContent()
}
// Reactive observation
viewModelScope.launch {
connectivityHelper.statusFlow.collect { status ->
when (status) {
is NetworkStatus.Available -> showOnlineMode()
is NetworkStatus.Unavailable -> showOfflineBanner()
is NetworkStatus.Losing -> Unit
}
}
}Content copied to clipboard
Properties
Link copied to clipboard
A Flow that emits NetworkStatus whenever the network connectivity changes. It emits the current status immediately upon subscription.
Functions
Link copied to clipboard
Transport actif, ou null si hors ligne.
Link copied to clipboard
true si une connexion réseau validée est disponible.