Retrofit 2我目前正在使用,我想在我的服务器上传一些照片.我知道,旧版本使用TypedFile类进行上传.如果我们想要使用进度条,我们应该writeTo在TypedFile类中重写方法.
使用retrofit 2库时是否可以显示进度?
我是新来的改造.我搜索过但没有找到简单的答案.我想知道如何在通知栏中显示下载进度或至少显示进度对话框,该对话框指定进程的百分比和下载文件的大小.这是我的代码:
public interface ServerAPI {
@GET
Call<ResponseBody> downlload(@Url String fileUrl);
Retrofit retrofit =
new Retrofit.Builder()
.baseUrl("http://192.168.43.135/retro/")
.addConverterFactory(GsonConverterFactory.create())
.build();
}
public void download(){
ServerAPI api = ServerAPI.retrofit.create(ServerAPI.class);
api.downlload("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png").enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
File path = Environment.getExternalStorageDirectory();
File file = new File(path, "file_name.jpg");
FileOutputStream fileOutputStream = new FileOutputStream(file);
IOUtils.write(response.body().bytes(), fileOutputStream);
}
catch (Exception ex){
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
}
});
}
Run Code Online (Sandbox Code Playgroud)
如果可以,请指导我.谢谢
我目前正在使用Retrofit 2,我想从我的服务器下载一些文件.我可以回拨一些事件来捕获百分比完整的下载文件,以显示在此图片的通知中
我引用那个链接,但它是上传,我可以用同样的问题吗? 链接
使用改造2库时是否可以显示进度?