gpt4 book ai didi

android - DownloadManager 不开始下载

转载 作者:行者123 更新时间:2023-11-29 02:35:38 26 4
gpt4 key购买 nike

我正在使用 downloadManager,但它没有下载任何内容。当我开始下载文件时,它被放置在队列列表中并且永远不会开始下载。这是我的代码:

webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, final String contentDisposition, final String mimeType, long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));

request.setMimeType(mimeType);
//------------------------COOKIE!!------------------------
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
//------------------------COOKIE!!------------------------
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimeType));
DownloadManager dm = (DownloadManager) activity.getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(activity.getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show();
}
});

如果我调试,所有值似乎都是正确的。此代码适用于 Android 6.0,但当我尝试使用 Android 7.0 时它不起作用。

有什么帮助吗?

非常感谢!!

最佳答案

您是在请求 WRITE_EXTERNAL_STORAGE 权限吗?

关于android - DownloadManager 不开始下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47295687/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com