java.lang.SecurityException: 不支持的路径 path/path/JPEG_5e3bbe8ed6c75_24741_.jpg

Bha*_*ghi 5 android download android-download-manager

这不适用于某些设备。在三星设备中,他们不允许使用下载管理器下载文件。我已经在清单中定义了权限并获得了运行时权限。

DownloadManager downloadManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setTitle("");
request.setDescription("");
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationUri(Uri.fromFile(imageFile));
request.setMimeType("*/*");
downloadManager.enqueue(request);
Run Code Online (Sandbox Code Playgroud)

Sha*_*aon 5

用这个

setDestinationInExternalFilesDir(
            context.applicationContext,
            Environment.DIRECTORY_DOWNLOADS,
            ""
        )
Run Code Online (Sandbox Code Playgroud)


Mus*_*led 1

我猜想如果您在 Marshamellow+ 上运行下载管理器,则存在运行时权限问题,因此您应该请求运行时权限,在清单文件中添加权限是不够的。检查官方文档的运行时权限,它会指导您解决问题。

注意:我们应该请求存储权限,因为它被视为危险权限。另一方面,我们不必请求互联网许可,因为这是正常的。我希望这足够了。