开发者

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_开发者_Python百科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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜