1

Is there a way to get progress data, to display ProgressBar(Horizontal), using DefaultHttpClient with image encoded to Base64 in params. I am also sending some other params. Similar thing is achieved in iOS .Is there any workout for Android.

EDIT

HttpRequestBase request;
if(mode == MODE.POST)
  request = new HttpPost(((Context) mWeakreReference.get()).getString(R.string.base_url)+ url);

 request.setHeader(UrlService.HEADER_API_CONTENT_TYPE_KEY, UrlService.HEADER_API_CONTENT_TYPE_VALUE);
 request.setHeader(UrlService.HEADER_DEVICE_ID, Utility.getDeviceId(mWeakreReference.get()));
DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = httpClient.execute(request);

Image and data is posted neatly . I have to display progress bar how can I achieve that.

Urban Pendu
  • 33
  • 1
  • 4

1 Answers1

2

not sure if you're still looking for an answer, but after spending some time looking for an answer online, I built my own tiny library: https://github.com/licryle/HTTPPoster

It's based of an StockOverflow answer, and another article found online.

The former uses deprecated Classes, and the latter doesn't show the Entities. It wraps the whole in an ASync task.

To use:

  1. Download & extract
  2. In your build.gradle Module file, add the dependency:
dependencies 
{    
     compile project(':libs:HTTPPoster') 
}
  1. You need a class to implement the HttpListener interface so you can listen to the callbacks. It has four callbacks in HTTPListener:

    • onStartTransfer
    • onProgress
    • onFailure
    • onResponse
  2. Configure the ASyncTask & start it. Here's a quick usage:

HashMap<String, String> mArgs = new HashMap<>();
mArgs.put("lat", "40.712784");
mArgs.put("lon", "-74.005941");

ArrayList<File> aFileList = getMyImageFiles();

HttpConfiguration mConf = new HttpConfiguration(
    "http://example.org/HttpPostEndPoint",
    mArgs,
    aFileList,
    this, // If this class implements HttpListener
    null,  // Boundary for Entities - Optional
    15000  // Timeout in ms for the connection operation
    10000, // Timeout in ms for the reading operation
);

new HttpPoster().execute(mConf);

hope that can help :) Feel also free to suggest improvements! It's very recent, and I extend it as I need it

Cheers

licryle
  • 41
  • 5