Coder Social home page Coder Social logo

Comments (2)

wyouflf avatar wyouflf commented on July 3, 2024

最新的策略:

                    if (contentLength < Integer.MAX_VALUE) {
                        connection.setFixedLengthStreamingMode((int) contentLength);
                    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        connection.setFixedLengthStreamingMode(contentLength);
                    } else {
                        connection.setChunkedStreamingMode(256 * 1024);
                    }

如果还有问题就是rom的问题, (setFixedLengthStreamingMode (J)V, 参数J对应java里的long)

from xutils3.

Jeffery336699 avatar Jeffery336699 commented on July 3, 2024

请问大神contentLength 和 connection分别是从哪里获得的?
`private void downFromServer() {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
String savePath= getFilesDir().getPath()+"/updata.apk";
Log.i(TAG, "downFromServer: ---savePath:"+savePath);
//设置请求参数
RequestParams params = new RequestParams(downloadUrl);
params.setAutoResume(true);//设置是否在下载是自动断点续传
params.setAutoRename(false);//设置是否根据头信息自动命名文件
params.setSaveFilePath("savePath");
params.setExecutor(new PriorityExecutor(2, true));//自定义线程池,有效的值范围[1, 3], 设置为3时, 可能阻塞图片加载.
params.setCancelFast(true);//是否可以被立即停止.
//下面的回调都是在主线程中运行的,这里设置的带进度的回调

        cancelable = x.http().get(params, new Callback.ProgressCallback<File>() {
            @Override
            public void onCancelled(CancelledException arg0) {
                Log.i("tag", "取消"+Thread.currentThread().getName());
            }

            @Override
            public void onError(Throwable arg0, boolean arg1) {
                Log.i("tag", "onError: 失败"+Thread.currentThread().getName());
                progressDialog.dismiss();
            }

            @Override
            public void onFinished() {
                Log.i("tag", "完成,每次取消下载也会执行该方法"+Thread.currentThread().getName());
                progressDialog.dismiss();
            }

            @Override
            public void onSuccess(File arg0) {
                Log.i("tag", "下载成功的时候执行"+Thread.currentThread().getName());
            }

            @Override
            public void onLoading(long total, long current, boolean isDownloading) {
                if (isDownloading) {
                    //                    progressDialog.setProgress((int) (current*100/total));
                    progressDialog.setProgress((int) (current*100/total));
                    Log.i("tag", "下载中,会不断的进行回调:"+Thread.currentThread().getName());
                }
            }

            @Override
            public void onStarted() {
                Log.i("tag", "开始下载的时候执行"+Thread.currentThread().getName());
                progressDialog.show();
            }

            @Override
            public void onWaiting() {
                Log.i("tag", "等待,在onStarted方法之前执行"+Thread.currentThread().getName());
            }

        });
    }else {
        Toast.makeText(this, "没有sd卡", Toast.LENGTH_SHORT).show();
    }

}`

报错:Could not find method java.net.HttpURLConnection.setFixedLengthStreamingMode, referenced from method org.xutils.http.request.HttpRequest.sendRequest

image请问大神哪里出错了

from xutils3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.