I use volley and asyntasks to download data from a VPS and display it in fragments and activities. I encounter this error a lot when I am connected to a public network and the network signal is (very) weak. I use a simple network checking function in the app to display a toast when I am not connected to any network. In these cases the activities don't start and the Toast is displayed. However, when I'm online and the network signal is very weak, the activity starts, Volley runs and throws an error
java.net.ConnectException: failed to connect to www.website.com/XX.XX.XX.XXX (port 80) after 2500ms: isConnected failed: EHOSTUNREACH (where Xs are the server address).
In this state of the app when I click on a navdrawer item it opens the activity and throws the same error. This is how I check for connection:
public static boolean isInternetAvailable(Context context)
{
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectivityManager.getActiveNetworkInfo();
if (info == null) {
Log.d(TAG,"no internet connection");
return false;
}
else
{
if(info.isConnected()) {
Log.d(TAG," internet connection available...");
return true;
}
else {
Log.d(TAG," noninternet connection");
return false;
}
}
}
Do you have any ideas on solving this error or upgrading my network checking function to check for weak network signal?