In android, i have this URL to which i must do a POST request the returned inputstream of said request returns a downloadable object... How can I use the Android Downloadmanager itself, or a custom created one, to handle the downloading process for me?
- What is your target API?Gaurav Agarwal– Gaurav Agarwal2013-03-03 14:10:47 +00:00Commented Mar 3, 2013 at 14:10
- minimum suported 2.3.6 development on a 4.1 tablet, but it's mainly intended for 2.3.6jaggy– jaggy2013-03-03 14:14:06 +00:00Commented Mar 3, 2013 at 14:14
- See if this stackoverflow.com/questions/2323617/… helps.Gaurav Agarwal– Gaurav Agarwal2013-03-03 14:20:24 +00:00Commented Mar 3, 2013 at 14:20
- I had to write a seperate class to handle the download & progressbar manually, quite like the following ootooban.com/en/2012/…jaggy– jaggy2013-03-03 15:21:47 +00:00Commented Mar 3, 2013 at 15:21
2 Answers
http://ootooban.com/en/2012/custom-download-manager-for-android-2-1-part2-resumable-downloads/
Creating your own notification ontop of a post request, combined with a setProgress() & progressbar did the trick, so there is no conclusive way of using the DownloadManager sadly enough
Comments
the android's Download manager is quite simple :
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); Request request = new Request(Uri.parse("http://www.theeUrl.fake/image.png")); enqueue = dm.enqueue(request); you can easily add parameter as its a GET request. I don't know if you can make a POST request from it.
EDIT : to make a post request you can use an HttpClient like this :
HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); HttpResponse response = null; Dictionary<String, String> postFields = new Dictionary<String, String>(); // Set the post fields postFields.add("username","toto"))); postFields.add("password", "thePassword45155"))); post.setEntity(new UrlEncodedFormEntity(postFields, HTTP.UTF_8)); // Execute the POST request response = client.execute(post); you should be able to get an inputstream from the httpResponse to download the file. but you'll have to manage display / notification / cancellation... yourself.