Created
April 22, 2019 08:41
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
USAGE
NetworkUtil.isConnected(Context Reference)