gpt4 book ai didi

安卓下载管理器.ERROR_FILE_ERROR

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:46:27 25 4
gpt4 key购买 nike

Possible duplicate

我正在使用 Android DownloadManager 下载大型 zip 文件。我有显示所有 zip 文件列表的 ListView ,用户可以点击项目开始下载。一次只能下载一个项目。当新列表项开始下载而其他下载正在进行时,我从队列中删除以前的下载 ID。一切正常。但有时我在 LG g2 设备操作系统 5.0.2 上收到 ERROR_FILE_ERROR。这是代码:

Uri uri = Uri.parse(path);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setAllowedOverRoaming(false);
request.setVisibleInDownloadsUi(false);

String localStorageBasePath = FileUtils.zipDirectory(context).getAbsolutePath() + File.separator + fileName;
Uri localStorageBasePathUri = Uri.fromFile(new File(localStorageBasePath));
request.setDestinationUri(localStorageBasePathUri);
Long downloadId = downloadManager.enqueue(request);

它在其他设备上运行良好,包括 nexus 5、三星 s3、note2、华为等。当我开始下载文件时,它立即停止/失败,原因是 DownloadManager.ERROR_FILE_ERROR。我试图删除/清理外部存储目录,确保它不是 ERROR_INSUFFICIENT_SPACE 错误等,但它没有用。有帮助吗?

最佳答案

这可能更防弹一点:

public void file_download(String path, String filename) 
{
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).mkdirs();

Uri uri = Uri.parse(path);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setDescription("");
request.setTitle("");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
{
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setAllowedOverRoaming(false);
request.setVisibleInDownloadsUi(false);
request.setDestinationInExternalFilesDir(context, DIRECTORY_DOWNLOADS, fileName);

//String localStorageBasePath = FileUtils.zipDirectory(context).getAbsolutePath() + File.separator + fileName;
//Uri localStorageBasePathUri = Uri.fromFile(new File(localStorageBasePath));
//request.setDestinationUri(localStorageBasePathUri);
DownloadManager downloadManager = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE);
Long downloadId = downloadManager.enqueue(request);
}

关于安卓下载管理器.ERROR_FILE_ERROR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40349725/

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