2

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.

Sherif elKhatib
  • 45,786
  • 16
  • 89
  • 106
nala4ever
  • 757
  • 2
  • 8
  • 18

1 Answers1

4

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
Sherif elKhatib
  • 45,786
  • 16
  • 89
  • 106