gpt4 book ai didi

android - 下载管理器在使用平台默认值的 Android Pie 9.0 NetworkSecurityConfig : No Network Security Config specified, 中不起作用

转载 作者:行者123 更新时间:2023-12-02 12:21:48 24 4
gpt4 key购买 nike

将设备操作系统更新到 Android 9.0 时,之前此代码运行良好(小米 A2)。现在,Android Pie 9.0 上无法下载文件。

此外,它在奥利奥、牛轧糖、棉花糖中运行良好

这是代码 fragment :

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

如有任何帮助,我们将不胜感激。谢谢

最佳答案

小米 A2 今天收到软件更新通知后,这对我有用。

enter image description here

什么对我有用

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,如下图

enter image description here

This explains the issue in software

关于android - 下载管理器在使用平台默认值的 Android Pie 9.0 NetworkSecurityConfig : No Network Security Config specified, 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53493077/

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