ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] allNetworkInfo = connectivityManager.getAllNetworkInfo(); for (NetworkInfo networkInfo : allNetworkInfo) { // Retrieve information about each network connection String type = networkInfo.getTypeName(); boolean isConnected = networkInfo.isConnected(); // ... }
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] allNetworkInfo = connectivityManager.getAllNetworkInfo(); for (NetworkInfo networkInfo : allNetworkInfo) { if (networkInfo.isConnected()) { // An active network connection is available // Proceed with network-dependent tasks } }Package library: The ConnectivityManager class is part of the android.net package.