Skip to content

Instantly share code, notes, and snippets.

@peterpazmandi
Last active July 14, 2020 14:09
Show Gist options
  • Save peterpazmandi/66f5013331bff0cc4c654fef241808d3 to your computer and use it in GitHub Desktop.
Save peterpazmandi/66f5013331bff0cc4c654fef241808d3 to your computer and use it in GitHub Desktop.
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkInfo
object ConnectivityUtil
{
fun isConnected(context: Context): Boolean
{
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork: NetworkInfo? = cm.activeNetworkInfo
return activeNetwork?.isConnectedOrConnecting == true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment