Android可达性测试
我有一个关于如何检查某个网址的可达性的问题。我可以通过 httpget url 连接来做到这一点。
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);
但我想用这种方式来做。
ConnectivityManager cm = (ConnectivityManager) TabViewActivity.this.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean test = cm.requestRouteToHost(ConnectivityManager.TYPE_WIFI,
lookupHost(HOST_IP));
但问题是布尔值总是返回 flase。
如果您对这个问题有任何想法,这将会有很大的帮助。
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
requestRouteToHost
不适用于type_wifi
requestRouteToHost
方法可以正确返回整数值,因为它适用于type_mobile.
Type_wifi
是它无法使用的类型。不过您需要权限:
requestRouteToHost
doesnt work withtype_wifi
requestRouteToHost
method returns the integer value correctly since it works withtype_mobile
.Type_wifi
is the one which it doesnt work with.Nevertheless You need permissions :