Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download file with download progress in % #53

Open
hashtaag-vinay-sasalatti opened this issue Jul 5, 2016 · 3 comments
Open

Download file with download progress in % #53

hashtaag-vinay-sasalatti opened this issue Jul 5, 2016 · 3 comments

Comments

@hashtaag-vinay-sasalatti

Hi , i am not able to find any sample implementation to do this , before i was using volley and now i chose to use volleyPlus only to get the download progress %, and now i am unable to implement this , can anyone help me with a sample or any snippet to get download progress

thanks ,
Vinay

@Kirkan
Copy link

Kirkan commented Sep 22, 2016

SimpleMultiPartRequest jsonRequest = new SimpleMultiPartRequest(Request.Method.POST, URL, 
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        Log.i(getClass().getName(), response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e(getClass().getName(), error.toString());
            }
        }) ;
        jsonRequest.addFile("images", IMAGE_PATH);
        jsonRequest.setFixedStreamingMode(true);
jsonRequest.setOnProgressListener(new Response.ProgressListener() {
            @Override
            public void onProgress(long transferredBytes, long totalSize) {
                int percentage = (int) ((transferredBytes / ((float) totalSize)) * 100);

            }
        });
        RequestQueue mRequestQueue = Volley.newRequestQueue(getApplicationContext());
        mRequestQueue.add(jsonRequest);
        mRequestQueue.start();

Another question: how to update the progress bar in notification from service?

@Kirkan
Copy link

Kirkan commented Sep 27, 2016

Prevent UI lag when update progress http://stackoverflow.com/a/23107289/2127124

@Hitexroid
Copy link

Hitexroid commented May 10, 2018


    public void DownloadFile(String url, String path) {
        DownloadRequest downloadRequest = new DownloadRequest(url, path, new Response.Listener<String>() {
            @Override
            public void onResponse(String path) {
                Log.d("saved in",path);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Log.d("volleyError", volleyError.toString());
            }
        });

        downloadRequest.setOnProgressListener(new Response.ProgressListener() {
            @Override
            public void onProgress(long downloaded, long totalSize) {
                int percentage = (int) ((downloaded / ((float) totalSize)) * 100);
                Log.d("percentage", String.valueOf(percentage) + "%");
            }
        });

        RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
        requestQueue.add(downloadRequest);
        requestQueue.start();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants