在上传文件期间改进进度条

时间:2015-12-04 08:44:52

标签: android retrofit android-progressbar

我需要实现一个显示上传视频的进度条,但我没有找到上传时获得进度的位置。这是我的代码:

ServiceGenerator.class

public class ServiceGenerator {

    public static final String API_BASE_URL = "url";

    private static RestAdapter.Builder builder = new RestAdapter.Builder()
            .setEndpoint(API_BASE_URL)
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setClient(new OkClient(new OkHttpClient()));

    public static <S> S createService(Class<S> serviceClass) {
        RestAdapter adapter = builder.build();
        return adapter.create(serviceClass);
    }
}

FileUploadService.class

public interface FileUploadService {
    @Multipart
    @POST("/")
    void upload(@Part("myfile") TypedFile file,
                @Part("hash") String hash,
                Callback<String> cb);
}

MainActivity.class

 FileUploadService service = ServiceGenerator.createService(FileUploadService.class);
                TypedFile typedFile = new TypedFile("multipart/form-data", new File(realPath));
                String hash = "JZzdFypunqDS5Ug";

                service.upload(typedFile, hash, new Callback<String>() {
                    @Override
                    public void success(String s, Response response) {
                        Log.e("Upload", "success");
                    }

                    @Override
                    public void failure(RetrofitError error) {
                        Log.e("Upload", "error");
                    }
                });

0 个答案:

没有答案