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

Multipart request progress bar ui stuck #75

Open
SilverFoxA opened this issue Apr 21, 2018 · 1 comment
Open

Multipart request progress bar ui stuck #75

SilverFoxA opened this issue Apr 21, 2018 · 1 comment

Comments

@SilverFoxA
Copy link

I have implemented the simple multipart request which also includes setOnProgressListener but the method doesn't get called hence progress bar doesn't show updated progress.

Here's my implementation

 final int[] percentDone = {0};
    param.put("uid", new SQLiteHandler(context).getUserDetails().get("uid"));
    SimpleMultiPartRequest jsonRequest = new SimpleMultiPartRequest(Request.Method.POST, URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    listener.success(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error != null && error.getCause() != null && error.getMessage() != null) {
                Log.d(tag, error.getMessage() + "");
            } else
                Log.d(tag, "Nothing");
            listener.error(error);
        }
    });

    for (String string :
            param.keySet()) {
        jsonRequest.addMultipartParam(string, "text/plain",
                param.get(string));
    }

    // jsonRequest.setFixedStreamingMode(true);

    jsonRequest.setOnProgressListener(new Response.ProgressListener() {
        @Override
        public void onProgress(long transferredBytes, long totalSize) {
            System.out.println(">>>>>>" + transferredBytes);
            final int latestPercentDone = (int) ((transferredBytes / (float) totalSize) * 100);

            if (percentDone[0] != latestPercentDone) {
                percentDone[0] = latestPercentDone;
                if (progressDialog != null)
                    progressDialog.setProgress(percentDone[0]);
            }
            if (BuildConfig.DEBUG) Log.d(tag, percentDone[0] + "");

            if (transferredBytes >= totalSize && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
        }
    });
    RequestQueue mRequestQueue = Volley.newRequestQueue(context);
    mRequestQueue.add(jsonRequest);
    mRequestQueue.start();
@larrytech7
Copy link

Do your files get uploaded?

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

2 participants