
Mobile network connectivity checker exposing current connection status, observable state flows, and an NPE-safe factory returning a no-op instance before app context initialization; published to Maven Central.
A Kotlin Multiplatform library for checking the network connectivity status of a mobile device.
This fork is maintained at omkardharmesh/konnectivity and adds:
Konnectivity() factory — returns a no-op KonnectivityImpl(NONE) when called before androidx.startup has populated the application context, instead of throwing.com.android.kotlin.multiplatform.library DSL, gradle/libs.versions.toml version catalog, com.vanniktech.maven.publish plugin.minSdk = 21, compileSdk = 36)iosArm64, iosSimulatorArm64) — physical device required for WIFI / CELLULAR reporting on iOSmavenCentral() is the only repository required. No credentials needed.
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}Add the dependency to your KMP commonMain source set:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("io.github.omkardharmesh:konnectivity:0.0.2")
}
}
}Create a single instance of Konnectivity and inject it:
val konnectivity: Konnectivity = Konnectivity()Read the current status:
val isConnected: Boolean = konnectivity.isConnected
when (konnectivity.currentNetworkConnection) {
NetworkConnection.NONE -> "Not connected to the internet"
NetworkConnection.WIFI -> "Connected to wifi"
NetworkConnection.CELLULAR -> "Connected to cellular"
}Observe changes via StateFlow:
scope.launch {
konnectivity.isConnectedState.collect { isConnected ->
// react
}
}
scope.launch {
konnectivity.currentNetworkConnectionState.collect { connection ->
when (connection) {
NetworkConnection.NONE -> "Not connected to the internet"
NetworkConnection.WIFI -> "Connected to wifi"
NetworkConnection.CELLULAR -> "Connected to cellular"
}
}
}Maintainer workflow — Central Portal account, GPG keypair, version bump, release command, troubleshooting — lives in PUBLISHING.md.
Quick release (after one-time setup):
# 1. bump version in konnectivity/build.gradle.kts + README
# 2. commit + tag + push
./publish.shiOS klibs require a macOS host. Artifact appears at central.sonatype.com/artifact/io.github.omkardharmesh/konnectivity within ~10 minutes.
Forked from Plus-Mobile-Apps/konnectivity (MIT) by Andrew Steinmetz.
A Kotlin Multiplatform library for checking the network connectivity status of a mobile device.
This fork is maintained at omkardharmesh/konnectivity and adds:
Konnectivity() factory — returns a no-op KonnectivityImpl(NONE) when called before androidx.startup has populated the application context, instead of throwing.com.android.kotlin.multiplatform.library DSL, gradle/libs.versions.toml version catalog, com.vanniktech.maven.publish plugin.minSdk = 21, compileSdk = 36)iosArm64, iosSimulatorArm64) — physical device required for WIFI / CELLULAR reporting on iOSmavenCentral() is the only repository required. No credentials needed.
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}Add the dependency to your KMP commonMain source set:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("io.github.omkardharmesh:konnectivity:0.0.2")
}
}
}Create a single instance of Konnectivity and inject it:
val konnectivity: Konnectivity = Konnectivity()Read the current status:
val isConnected: Boolean = konnectivity.isConnected
when (konnectivity.currentNetworkConnection) {
NetworkConnection.NONE -> "Not connected to the internet"
NetworkConnection.WIFI -> "Connected to wifi"
NetworkConnection.CELLULAR -> "Connected to cellular"
}Observe changes via StateFlow:
scope.launch {
konnectivity.isConnectedState.collect { isConnected ->
// react
}
}
scope.launch {
konnectivity.currentNetworkConnectionState.collect { connection ->
when (connection) {
NetworkConnection.NONE -> "Not connected to the internet"
NetworkConnection.WIFI -> "Connected to wifi"
NetworkConnection.CELLULAR -> "Connected to cellular"
}
}
}Maintainer workflow — Central Portal account, GPG keypair, version bump, release command, troubleshooting — lives in PUBLISHING.md.
Quick release (after one-time setup):
# 1. bump version in konnectivity/build.gradle.kts + README
# 2. commit + tag + push
./publish.shiOS klibs require a macOS host. Artifact appears at central.sonatype.com/artifact/io.github.omkardharmesh/konnectivity within ~10 minutes.
Forked from Plus-Mobile-Apps/konnectivity (MIT) by Andrew Steinmetz.