Android P,下载没有开始使用下载管理器?

时间:2018-05-11 06:17:23

标签: java android android-8.0-oreo android-9.0-pie

我正在尝试使用下载管理器下载文件,并且下载似乎没有在Android P上启动(在模拟器上运行)。它适用于Android Oreo和Android Marshmallow。这是代码。

DownloadManager.Request downloadRequest = new DownloadManager.Request(Uri.parse(URLS.URLforDownloadingFileData(fileName)));
        File file = new File(mobileInfo.getExternalFileStorageDirectory(),fileName);
        downloadRequest.setDestinationUri(Uri.fromFile(file));
        downloadRequest.setTitle(titleOfDownload);
        downloadRequest.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
        downloadManager.enqueue(downloadRequest);

知道为什么会发生这种情况以及如何解决这个问题?与Android P中引入的更改有什么关系?

1 个答案:

答案 0 :(得分:2)

似乎您已经定义了NetworkSecurityPolicy用于下载URL主机。 您可以通过创建XML res/xml/network_security_config.xml来检查它:

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

然后在您的AndroidManifest.xml内的Application标签中引用此文件:

android:networkSecurityConfig="@xml/network_security_config"

如果可行-强烈建议不要对所有主机进行流量管理,而仅对需要的主机进行流量管理。

相关问题