Created
January 19, 2015 11:44
-
-
Save acacha/b59aa63d8fed9347b929 to your computer and use it in GitHub Desktop.
isConnected Android. Check if device is connected
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
private static boolean isConnected(Context context) { | |
ConnectivityManager connectivityManager = (ConnectivityManager) | |
context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo networkInfo = null; | |
if (connectivityManager != null) { | |
networkInfo = | |
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); | |
} | |
return networkInfo == null ? false : networkInfo.isConnected(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, when connecting WiFi, networkInfo.isConnected () to return to false, you have encountered this problem, I am very strange.
Environment: Xiaomi Android 5.1.1