在Android中,我有一个URL需要进行POST请求,该请求返回可下载的对象的输入流... 我该如何使用Android Downloadmanager本身或自定义的下载管理器来处理下载过程?
http://ootooban.com/en/2012/custom-download-manager-for-android-2-1-part2-resumable-downloads/
创建自己的通知并结合 setProgress() 和进度条来处理 post 请求,这样就可以解决问题了。遗憾的是,使用 DownloadManager 没有确定的方法。Android 的下载管理器非常简单:
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Request request = new Request(Uri.parse("http://www.theeUrl.fake/image.png"));
enqueue = dm.enqueue(request);
由于这是一个GET请求,您可以轻松地添加参数。我不知道您是否可以从中发出POST请求。
编辑:要发出POST请求,您可以使用类似以下的HttpClient:
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);
你应该能够从httpResponse获取一个inputstream来下载文件。 但是你需要自己管理显示/通知/取消操作。