Search code examples
javaandroidreachability

Android Reachability test


I have an issue regarding how to check the reachability of a certain url. I can do it with a httpget url connection.

HttpGet httpGet = new HttpGet(HOST_URL);
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 5000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
int timeoutSocket = 8000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(httpGet);

But i want to do it with this way.

ConnectivityManager cm = (ConnectivityManager) TabViewActivity.this.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean test = cm.requestRouteToHost(ConnectivityManager.TYPE_WIFI,
                            lookupHost(HOST_IP));

But the problem is the boolean always returns flase.

If you have any ideas about this issue it will be a big help.

Thanks in advance.


Solution

  • requestRouteToHost doesnt work with type_wifi

    requestRouteToHost method returns the integer value correctly since it works with type_mobile.

    Type_wifi is the one which it doesnt work with.

    Nevertheless You need permissions :

    ACCESS_NETWORK_STATE
    
    ACCESS_WIFI_STATE