【发布时间】:2015-07-22 12:04:45
【问题描述】:
我想在 libgdx 中使用 volley 或 okhttp 从 Web 加载一些数据。
如何在 libgdx 中使用 volley 或 okhttp 等网络框架而不是 libgdx networking class ?
【问题讨论】:
标签: android libgdx android-volley okhttp
我想在 libgdx 中使用 volley 或 okhttp 从 Web 加载一些数据。
如何在 libgdx 中使用 volley 或 okhttp 等网络框架而不是 libgdx networking class ?
【问题讨论】:
标签: android libgdx android-volley okhttp
例如尝试将此compile 'com.squareup.okhttp:okhttp:2.3.0' 添加到您的项目build.gradle 文件中
project(":core") {
apply plugin: "java"
dependencies {
...
compile 'com.squareup.okhttp:okhttp:2.3.0'
}
}
然后你可以在你的核心项目中使用 okhttp 这里是一个例子:
public class OkhttpTest extends ApplicationAdapter {
OkHttpClient client = new OkHttpClient();
@Override
public void create() {
try {
System.out.println(run("http://google.com"));
} catch (IOException e) {
e.printStackTrace();
}
}
String run(String url) throws IOException {
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
}
【讨论】: