Created
March 21, 2018 00:58
-
-
Save cdmunoz/1d361f751762cb96f8175a1e24368ad2 to your computer and use it in GitHub Desktop.
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
class Utils @Inject constructor(private val context: Context) { | |
fun isConnectedToInternet(): Boolean { | |
val connectivity = context.getSystemService( | |
Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
if (connectivity != null) { | |
val info = connectivity.allNetworkInfo | |
if (info != null) | |
for (i in info.indices) | |
if (info[i].state == NetworkInfo.State.CONNECTED) { | |
return true | |
} | |
} | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment