带进度条的Volley Multipart请求

时间:2016-07-18 18:04:59

标签: android file-upload progress-bar android-volley

如何在volly multipart请求中使用progressbar来上传图像。我正在使用VolleyPlus库来进行多部分请求。我的多部分请求代码是

SimpleMultiPartRequest smr = new SimpleMultiPartRequest(Request.Method.POST, BASE_URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.d("Response", response);
                    try {
                        JSONObject jObj = new JSONObject(response);
                        String message = jObj.getString("message");

                        Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();

                    } catch (JSONException e) {
                        // JSON error
                        e.printStackTrace();
                        Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
        }
    });

    smr.addFile("image", imagePath);
    smr.addMultipartParam("name", fileType, fileName);        
    MyApplication.getInstance().addToRequestQueue(smr);

现在我想添加上传文件的进度条,如下所示:

progress bar - 1

enter image description here

0 个答案:

没有答案