getActiveNetworkInfo()
is returning null
.
As documentation says,
Returns details about the currently active default data network. When
connected, this network is the default route for outgoing connections.
You should always check isConnected() before initiating network
traffic. This may return null when there is no default network.
Hence, plz make sure you have access to active network.
You can try following:
public static boolean isInternetAvailable(Context cxt) {
ConnectivityManager cm = (ConnectivityManager) cxt
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
Log.i("NetworkStatus :", "Network connection available.");
return true;
}
return false;
}