Short introduction, this is very simple internet checker, you can execute a function when the device disconnected and otherwise, you can check is connected to the internet for once on execution.
For installation just add this code in your app build.gradle file
implementation 'com.github.muhammadisa:lifemark:1.0.1'
Read the terms https://github.com/muhammadisa/lifemark/blob/master/CONTRIBUTING.md
Just click this link https://github.com/muhammadisa/lifemark/tree/master/example/src/main/java/com/xoxoer/example
-
Forever Checking
val networkConnection = Lifemark(applicationContext) networkConnection.ObservableNetworkCondition() .observe(this@MainActivity, Observer { isConnected -> if (isConnected) { // do something when device connected to internet } else { // do something when device disconnected to internet } })
-
Checking for once execution
val networkConnection = Lifemark(applicationContext) if(networkConnection.isNetworkConnected()){ // do something when device connected to internet }else{ // do something when device disconnected to internet }
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val networkConnection = Lifemark(applicationContext)
// Forever Checking example
networkConnection.ObservableNetworkCondition()
.observe(this@MainActivity, Observer { isConnected ->
if (isConnected) {
disconnected_layout.visibility = View.GONE
connected_layout.visibility = View.VISIBLE
} else {
connected_layout.visibility = View.GONE
disconnected_layout.visibility = View.VISIBLE
}
})
if (networkConnection.isNetworkConnected()) {
// do something when device connected to internet
Log.d("INTERNET_CHECKER", "true")
} else {
// do something when device disconnected to internet
Log.d("INTERNET_CHECKER", "false")
}
}
}
👤 Dimas Prasetya
- Github: @Dimas-Prasetya
👤 Muhammad Isa Wijaya Kusuma
- Github: @muhammadisa
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator