我想在libGDX项目中查看Wifi stat,尝试使用以下代码:
Gdx.net.sendHttpRequest(HttpRequest httpRequest, HttpResponseListener httpResponseListener);
HttpResponseListener httpResponseListener = new httpResponseListener() {
public void handleHttpResponse (HttpResponse httpResponse) {
HttpStatus status = httpResponse.getStatus();
if (status.getStatusCode() >= 200 && status.getStatusCode() < 300) {
// it was successful
} else {
// do something else
}
}
}
我添加了权限:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
它说HttpResponseListener cannot resolved
。
我该如何解决这个问题?
答案 0 :(得分:1)
// there is a small 'h' here, which is wrong ---v
HttpResponseListener httpResponseListener = new httpResponseListener() {
public void handleHttpResponse (HttpResponse httpResponse) {
HttpStatus status = httpResponse.getStatus();
if (status.getStatusCode() >= 200 && status.getStatusCode() < 300) {
// it was successful
} else {
// do something else
}
}
}
// here, you still have the parameter types
Gdx.net.sendHttpRequest(HttpRequest httpRequest, HttpResponseListener httpResponseListener);
// this is correct
Gdx.net.sendHttpRequest(httpRequest, httpResponseListener);
除此之外,这可能不起作用。如果没有互联网连接,您将无法从服务器获得响应。您必须覆盖HttpResponseListener.failed()。