A network helper library written in Kotlin for Android.
Add the code below to your root build.gradle
file (not your module build.gradle file).
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Then, add the code below to your module's build.gradle
file.
dependencies {
implementation 'com.github.Gondolav:ketwork:1.1.2'
}
Ketwork defines various Android Context extension functions to ease development tied to connectivity.
Here's how to execute some code based on whether Internet connection is on/off:
// Inside an Activity onCreate(), for example
runOnConnection {
on {
// download something from the web
}
off {
// show error popup
}
}
You can also use runIfConnected
and runIfDisconnected
:
runIfConnected {
// download something from the web
}
runIfDisconnected {
// show error popup
}
Of course, you can also just check for connectivity with isInternetConnectionOn()
.
Remember to add in your app manifest the ACCESS_NETWORK_STATE
permission, required to check for connectivity.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.