Skip to content

Instantly share code, notes, and snippets.

@alvareztech
Created September 4, 2017 19:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvareztech/46b9e346477e3a224bbd54164cc2c166 to your computer and use it in GitHub Desktop.
Save alvareztech/46b9e346477e3a224bbd54164cc2c166 to your computer and use it in GitHub Desktop.
Android: Check networking
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
Log.d("MIAPP", "Estás online");
Log.d("MIAPP", " Estado actual: " + networkInfo.getState());
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
// Estas conectado a un Wi-Fi
Log.d("MIAPP", " Nombre red Wi-Fi: " + networkInfo.getExtraInfo());
}
} else {
Log.d("MIAPP", "Estás offline");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment