下载Manger无法在Android Pie 9.0中运行NetworkSecurityConfig:未使用平台默认值指定网络安全配置 [英] Download Manger not working in Android Pie 9.0 NetworkSecurityConfig: No Network Security Config specified, using platform default
问题描述
在将设备操作系统更新为Android 9.0
时,此代码以前工作正常( Xiaomi mi A2 ).现在,文件不在Android Pie 9.0
上下载.
On updating the device OS to Android 9.0
, previously this code was working fine(Xiaomi mi A2). Now, files are not being downloaded on Android Pie 9.0
.
此外,它在Oreo,牛轧糖,棉花糖中都可以正常工作
这是代码段:
File myDir = new File(Environment.getExternalStorageDirectory(), "MyApp");
if (!myDir.exists()) {
myDir.mkdirs();
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
DownloadManager mgr = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Uri downloadUri = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(
downloadUri);
request.setAllowedNetworkTypes(
DownloadManager.Request.NETWORK_WIFI
| DownloadManager.Request.NETWORK_MOBILE).setAllowedOverMetered(true)
.setAllowedOverRoaming(true).setTitle("Downloading demo file").
setVisibleInDownloadsUi(true)
.setDestinationInExternalPublicDir(folder_main + "/", timeStamp);
mgr.enqueue(request);
logcat错误:
11-27 11:17:28.056 4062-2814/? D/DownloadManager: [3970] Starting
11-27 11:17:28.067 4062-2814/? W/DownloadManager: [3970] Stop requested with status HTTP_DATA_ERROR
11-27 11:17:28.068 4062-2814/? D/DownloadManager: [3970] Finished with status WAITING_TO_RETRY
11-27 11:18:06.466 4062-2843/? D/DownloadManager: [3970] Starting
11-27 11:18:06.576 4062-2843/? W/DownloadManager: [3970] Stop requested with status HTTP_DATA_ERROR
11-27 11:18:06.577 4062-2843/? D/DownloadManager: [3970] Finished with status WAITING_TO_RETRY
11-27 11:19:06.581 4062-2867/? D/DownloadManager: [3968] Starting
11-27 11:19:06.737 4062-2867/? W/DownloadManager: [3968] Stop requested with status HTTP_DATA_ERROR
11-27 11:19:06.738 4062-2867/? D/DownloadManager: [3968] Finished with status WAITING_TO_RETRY
11-27 11:19:19.131 4062-2869/? D/DownloadManager: [3970] Starting
11-27 11:19:19.144 4062-2869/? W/DownloadManager: [3970] Stop requested with status HTTP_DATA_ERROR
11-27 11:19:19.144 4062-2869/? D/DownloadManager: [3970] Finished with status WAITING_TO_RETRY
11-27 11:19:36.243 4062-2872/? D/DownloadManager: [3969] Starting
11-27 11:19:36.259 4062-2872/? W/DownloadManager: [3969] Stop requested with status HTTP_DATA_ER
任何帮助将不胜感激.谢谢
Any help would be appreciated. Thanks
推荐答案
这对我有用.在Xiaomi mi A2
今天收到软件更新通知之后.
This worked for me After Xiaomi mi A2
received software update notification today.
对我有用的东西
在application
标签中添加android:networkSecurityConfig="@xml/network_security_config"
<application
android:name=".ApplicationClass"
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
其中network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
在res
目录下创建xml
,然后在xml
文件夹中创建network_security_config.xml
,如下图所示
Create xml
under res
directory and then network_security_config.xml
in xml
folder like in the picture below
这篇关于下载Manger无法在Android Pie 9.0中运行NetworkSecurityConfig:未使用平台默认值指定网络安全配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!