其他分享
首页 > 其他分享> > 下载管理器返回的Android 9.0下载失败

下载管理器返回的Android 9.0下载失败

作者:互联网

我正在使用下载管理器从互联网下载文件.下载已在Android 6、8.1中成功完成,但在Android 9.0中未成功完成

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Downloading...");
request.setTitle(nameOfFile);
request.setMimeType("application/pdf");
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS + "/CPG", nameOfFile);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
queueId = manager.enqueue(request);

解决方法:

我在这里找到了解决方案:How to solve Android P DownloadManager stopping with “Cleartext HTTP traffic to 127.0.0.1 not permitted”?

简而言之,我只需要执行以下操作:

1.创建res / xml / network_security_config.xml,然后添加

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

2.在清单文件中,在应用程序标记内引用它

android:networkSecurityConfig="@xml/network_security_config"

欲了解更多信息,请点击这里:https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted

标签:android-9-0-pie,android-download-manager,android
来源: https://codeday.me/bug/20191024/1924221.html