I have code to download using multipart like this, in this code I have a progress bar
protected String doInBackground(String... args) { namapro = inputtitle.getText().toString(); hargapro = inputprice.getText().toString(); despro= inputdes.getText().toString(); orderpro = inputorder.getText().toString(); path = getIntent().getStringExtra("pathimage"); product.setTitle(namapro); product.setPrice(hargapro); product.setDesc(despro); product.setHow(orderpro); product.setImage(path); try{ CustomMultipartEntity multipartContent = new CustomMultipartEntity(new ProgressListener() { @Override public void transferred(long num) { int upload = ((int)((num/(float)totalSize)*100)); String progress = String.valueOf(upload); publishProgress(progress); } }); HttpEntity resEntity; HttpContext httpContext = new BasicHttpContext(); HttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(Constants.url_create_product); MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); File file= new File(path); FileBody bin = new FileBody(file); reqEntity.addPart("phone", new StringBody(mPhoneNumber)); reqEntity.addPart("prod_title", new StringBody(namapro)); reqEntity.addPart("prod_price", new StringBody(hargapro)); reqEntity.addPart("prod_desc", new StringBody(despro)); reqEntity.addPart("prod_order", new StringBody(orderpro)); reqEntity.addPart("prod_image", bin); totalSize = reqEntity.getContentLength(); post.setEntity(reqEntity); HttpResponse response = httpClient.execute(post); resEntity = response.getEntity(); String response_str = EntityUtils.toString(resEntity); Gson gson = new Gson(); gson.toJson(response_str); if (resEntity != null) {
But when I run this code, the progress bar did not show progressBar, not updating the process. I just see% 0 and% 100. How to solve this? may I help?
thanks
source share