Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@acacha
Created January 19, 2015 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acacha/b59aa63d8fed9347b929 to your computer and use it in GitHub Desktop.
Save acacha/b59aa63d8fed9347b929 to your computer and use it in GitHub Desktop.
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();
}
@df13954
Copy link

df13954 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