Last active
September 7, 2018 08:06
-
-
Save bapspatil/f34e96bcaa697e537e72855e99e151d9 to your computer and use it in GitHub Desktop.
A method that checks if the app is connected to the Internet or not.
This file contains hidden or 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
| fun hasNetwork(context: Context): Boolean? { | |
| var isConnected: Boolean? = false // Initial Value | |
| val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
| val activeNetwork: NetworkInfo? = connectivityManager.activeNetworkInfo | |
| if (activeNetwork != null && activeNetwork.isConnected) | |
| isConnected = true | |
| return isConnected | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment