Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
isConnected Android. Check if device is connected
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();
}
@ff-frida

This comment has been minimized.

Copy link

@ff-frida ff-frida commented Feb 23, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment