use of com.okhttplib.callback.ProgressCallback in project OkHttp3 by MrZhousf.
the class DownloadActivity method downloadFile.
private void downloadFile() {
final HttpInfo info = HttpInfo.Builder().addDownloadFile(fileURL, "myMP4", new ProgressCallback() {
@Override
public void onProgressMain(int percent, long bytesWritten, long contentLength, boolean done) {
downloadProgress.setProgress(percent);
tvResult.setText(percent + "%");
LogUtil.d(TAG, "下载进度:" + percent);
}
@Override
public void onResponseMain(String filePath, HttpInfo info) {
tvResult.setText(info.getRetDetail());
LogUtil.d(TAG, "下载结果:" + info.getRetDetail());
}
}).build();
OkHttpUtil.Builder().setReadTimeout(120).build(//绑定请求标识
requestTag).doDownloadFileAsync(info);
}
use of com.okhttplib.callback.ProgressCallback in project OkHttp3 by MrZhousf.
the class DownloadBreakpointsActivity method download.
private void download() {
if (null == fileInfo)
fileInfo = new DownloadFileInfo(url, "test", new ProgressCallback() {
@Override
public void onProgressMain(int percent, long bytesWritten, long contentLength, boolean done) {
downloadProgress.setProgress(percent);
tvResult.setText(percent + "%");
LogUtil.d(TAG, "下载进度:" + percent);
}
@Override
public void onResponseMain(String filePath, HttpInfo info) {
if (info.isSuccessful()) {
tvResult.setText(info.getRetDetail() + "\n下载状态:" + fileInfo.getDownloadStatus());
} else {
Toast.makeText(DownloadBreakpointsActivity.this, info.getRetDetail(), Toast.LENGTH_SHORT).show();
}
}
});
HttpInfo info = HttpInfo.Builder().addDownloadFile(fileInfo).build();
OkHttpUtil.Builder().setReadTimeout(120).build(this).doDownloadFileAsync(info);
}
use of com.okhttplib.callback.ProgressCallback in project OkHttp3 by MrZhousf.
the class UploadImageActivity method uploadImgTwo.
/**
* 上传第二张图片
*/
private void uploadImgTwo() {
HttpInfo info = HttpInfo.Builder().setUrl(url).addUploadFile("uploadFile", filePathTwo, new ProgressCallback() {
@Override
public void onProgressMain(int percent, long bytesWritten, long contentLength, boolean done) {
uploadProgressTwo.setProgress(percent);
LogUtil.d(TAG, "上传进度2:" + percent);
}
@Override
public void onResponseMain(String filePath, HttpInfo info) {
LogUtil.d(TAG, "上传结果2 Main:\n" + filePath + "\n" + info.getRetDetail());
}
@Override
public void onResponseSync(String filePath, HttpInfo info) {
LogUtil.d(TAG, "上传结果2 Sync:\n" + filePath + "\n" + info.getRetDetail());
}
}).build();
doUploadImg(info);
}
use of com.okhttplib.callback.ProgressCallback in project OkHttp3 by MrZhousf.
the class UploadFileActivity method uploadFile.
private void uploadFile(String path) {
if (TextUtils.isEmpty(path)) {
Toast.makeText(this, "请选择上传文件!", Toast.LENGTH_LONG).show();
return;
}
HttpInfo info = HttpInfo.Builder().setUrl(url).addUploadFile("uploadFile", path, new ProgressCallback() {
@Override
public void onProgressMain(int percent, long bytesWritten, long contentLength, boolean done) {
uploadProgress.setProgress(percent);
LogUtil.d(TAG, "上传进度:" + percent);
}
@Override
public void onResponseMain(String filePath, HttpInfo info) {
tvResult.setText(info.getRetDetail());
}
}).build();
OkHttpUtil.getDefault(this).doUploadFileAsync(info);
}
use of com.okhttplib.callback.ProgressCallback in project OkHttp3 by MrZhousf.
the class UploadFileActivity method doUploadBatch.
/**
* 单次批量上传:一次请求上传多个文件
*/
private void doUploadBatch() {
imgList.clear();
imgList.add("/storage/emulated/0/okHttp_download/test.apk");
// imgList.add("/storage/emulated/0/okHttp_download/test.rar");
HttpInfo.Builder builder = HttpInfo.Builder().setUrl(url);
//循环添加上传文件
for (String path : imgList) {
//若服务器为php,接口文件参数名称后面追加"[]"表示数组,示例:builder.addUploadFile("uploadFile[]",path);
builder.addUploadFile("uploadFile", path);
}
final HttpInfo info = builder.build();
new Thread(new Runnable() {
@Override
public void run() {
OkHttpUtil.getDefault(UploadFileActivity.this).doUploadFileSync(info, new ProgressCallback() {
@Override
public void onProgressMain(int percent, long bytesWritten, long contentLength, boolean done) {
uploadProgress.setProgress(percent);
LogUtil.d(TAG, "上传进度:" + percent);
}
@Override
public void onResponseMain(String filePath, HttpInfo info) {
LogUtil.d(TAG, "上传结果:" + info.getRetDetail());
tvResult.setText(info.getRetDetail());
}
});
}
}).start();
}
Aggregations