Skip to content

Multipart request progress bar ui stuck #75

Description

@SilverFoxA

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();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions