This light-weight library provides extension functions to existing Wifi-Manager API available on android to reduce boilerplate-code and simply some commonly used APIs. It also uses kotlin-coroutines to remove dependency on callbacks and broadcast-receivers.
WifiManager-Android-KTX requires Android Jellybean (API level 16) or higher.
To add this library in your project follow these steps:
-
Step 1. Add the JitPack repository to your root
build.gradle
file.allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
-
Step 2. Add the following dependency to your module
build.gradle
file.dependencies { implementation 'com.github.adwardstark:wifimanager-android-ktx:{latest_version}' }
These are the extensions that are available within this library:
- turnOnWifi() : Turn-on wifi on device prior to [
Android-Q
] and shows system-dialog on Q and above. - turnOffWifi() : Turn-off wifi on device prior to [
Android-Q
] and shows system-dialog on Q and above. - isWifiEnabled() : Returns true if wifi is enabled on device.
- isConnectedToWifi() : Returns true if the device is connected to a wifi-network.
- isConnectedToWifiOf(networkSSID: String): Returns true if the device is connected to provided SSID.
- wifiManager() : Returns the wifi-manager instance or null.
- wifiConnectionInfo() : Returns connection-information of current wifi-network or null.
- getWifiInfoOf(networkSSID: String) : Returns connection-information of provided SSID or null.
- getSSIDOfConnectedWifi() : Returns SSID of current wifi-network or null.
- getIPAddressOfConnectedWifi() : Returns IP-Address of connected wifi-network or null.
- getIPAddressFrom(info: WifiInfo) : Returns IP-Address from provided connection-information or null.
- getWifiScanResults() : Returns list of wifi-networks if available, uses [
suspendCancellableCoroutine{}
].
Apache 2.0. See the LICENSE file for details.