gpt4 book ai didi

android - DownloadManager 在 API 17 上失败并显示 ERROR_UNKNOWN

转载 作者:搜寻专家 更新时间:2023-11-01 09:46:09 25 4
gpt4 key购买 nike

我正在尝试使用 android 自己的 DownloadManager,它在 API 18+ 上完美运行,但同样的代码失败 (STATUS_FAILED),原因是 ERROR_UNKNOWN 几乎是在我将它排入 API 17 手机的队列中时。这是我的代码

Context context = MyApplication.getSharedContext();
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE).setTitle(notiTitle).
setVisibleInDownloadsUi(false);
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+fileName);
request.setDestinationUri(Uri.fromFile(file));
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request) ;

最佳答案

经过几天与这个问题的斗争,我无意中发现了问题的根源。从服务器获取的下载 URL 包含“[”和“]”字符。它们在 API 18+ DownloadManager 中没有问题,但在 API 17 中下载失败并显示 ERROR_UNKNOWN,没有任何关于原因的信息。分别用 %5B 和 %5D 替换它们解决了问题。

url = url.replace("[","%5B").replace("]","%5D");

关于android - DownloadManager 在 API 17 上失败并显示 ERROR_UNKNOWN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37976748/

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