Search in sources :

Example 21 with HttpInfo

use of com.okhttplib.HttpInfo 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);
}
Also used : HttpInfo(com.okhttplib.HttpInfo) DownloadFileInfo(com.okhttplib.bean.DownloadFileInfo) ProgressCallback(com.okhttplib.callback.ProgressCallback)

Aggregations

HttpInfo (com.okhttplib.HttpInfo)21 IOException (java.io.IOException)12 ProgressCallback (com.okhttplib.callback.ProgressCallback)10 Callback (com.okhttplib.callback.Callback)6 SocketTimeoutException (java.net.SocketTimeoutException)6 Request (okhttp3.Request)4 DownloadFileInfo (com.okhttplib.bean.DownloadFileInfo)3 SocketException (java.net.SocketException)3 UnknownHostException (java.net.UnknownHostException)3 Call (okhttp3.Call)3 Response (okhttp3.Response)3 NetworkOnMainThreadException (android.os.NetworkOnMainThreadException)2 CallbackMessage (com.okhttplib.bean.CallbackMessage)2 DownloadMessage (com.okhttplib.bean.DownloadMessage)2 UploadMessage (com.okhttplib.bean.UploadMessage)2 BaseCallback (com.okhttplib.callback.BaseCallback)2 ProgressResponseBody (com.okhttplib.progress.ProgressResponseBody)2 File (java.io.File)2 RandomAccessFile (java.io.RandomAccessFile)2 OkHttpClient (okhttp3.OkHttpClient)2