I wanted to create an extension function for Android built in ConnectivityManager
class so that it can be used statically by any class in my project. I am using Kotlin only.
fun ConnectivityManager.checkInternet(context: Context): Boolean {
val manager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val connection = manager.activeNetworkInfo
if (connection != null && connection.isConnectedOrConnecting) {
return true
}
return false
}
I can access this function by creating the object of ConnectivityManager
but what i want to do is to use it statically. Any possibility?