getActiveNetworkInfo returns null if there is no default connection available according to documents - > getActiveNetworkInfo . What I would advise you to do is check the networks, each individually, as shown below.
NetworkInfo WiFiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mobileInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
then check if they are available
if(mobileInfo != null & mobileInfo.isConnectedOrConnecting() || WiFiInfo != null & WiFiInfo.isConnectedOrConnecting()) { //do your task here } else { //show an alert dialog or something }
kevthanewversi
source share