Skip to content

Instantly share code, notes, and snippets.

@tizisdeepan
Created April 22, 2019 08:41
Show Gist options
  • Save tizisdeepan/61f0462a6ace800cda0ce285435fbfef to your computer and use it in GitHub Desktop.
Save tizisdeepan/61f0462a6ace800cda0ce285435fbfef to your computer and use it in GitHub Desktop.
Network utility class that helps in identifying whether there is a stable internet connection or not.
import android.content.Context
import android.net.ConnectivityManager
object NetworkUtil {
fun isConnected(context: Context): Boolean {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork = cm.activeNetworkInfo
return activeNetwork != null && activeNetwork.isConnectedOrConnecting
}
}
@tizisdeepan
Copy link
Author

tizisdeepan commented Apr 22, 2019

USAGE

NetworkUtil.isConnected(Context Reference)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment