【发布时间】:2019-12-31 11:14:04
【问题描述】:
我曾尝试使用 Android 的 DownloadManager api 下载,但未能成功。
这是我返回下载失败的示例代码。
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
DownloadManager.Request request = new DownloadManager.Request(
Uri.parse(url));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
DownloadManager dm = (DownloadManager) MainActivity.this.getSystemService(MainActivity.this.DOWNLOAD_SERVICE);
dm.enqueue(request);
}
});
【问题讨论】:
-
你可以添加适当的请求头来完成认证stackoverflow.com/questions/25669258/…
-
有什么解决办法吗?
标签: android android-download-manager ntlm-authentication