Android: Check networking
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
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