gpt4 book ai didi

android - 如何在 libgdx 中使用网络框架(volley、okhttp 等)?

转载 作者:太空宇宙 更新时间:2023-11-03 13:19:50 25 4
gpt4 key购买 nike

我想在 libgdx 中使用 volley 或 okhttp 从网络加载一些数据。
如何在 libgdx 中使用 volley 或 okhttp 等网络框架而不是 libgdx networking class

最佳答案

尝试将此 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();
}
}

关于android - 如何在 libgdx 中使用网络框架(volley、okhttp 等)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30176917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com