Created
March 21, 2018 00:54
-
-
Save cdmunoz/f69d14b3b7bedd19afdd651e5a32571e 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