Kotlin version:
fun isInternetOn(context: Context): Boolean {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
val activeNetwork = cm?.activeNetworkInfo
return activeNetwork != null && activeNetwork.isConnected
}