gpt4 book ai didi

android - 如何解决 Android P DownloadManager 以 "Cleartext HTTP traffic to 127.0.0.1 not permitted"停止?

转载 作者:可可西里 更新时间:2023-11-01 18:59:23 27 4
gpt4 key购买 nike

我已经定义了一个自定义网络安全配置,并按照建议将其包含在我的 list 中 here

res/xml/network_security_config.xml:

  <?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">127.0.0.1</domain>
<domain includeSubdomains="true">localhost</domain>
</domain-config>
</network-security-config>

这是在我的 Android.manifest 中:

    <application android:icon="@drawable/icon" 
android:allowBackup="false"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:persistent="true" >

即使在尝试通过 HTTP 与 127.0.0.1 通信时进行了这些更改,我仍会在 logcat 中看到:

08-09 10:50:34.395 30791  3607 D NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
08-09 10:50:34.397 30791 3607 D NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
08-09 10:50:34.401 30791 3607 W DownloadManager: [647] Stop requested with status HTTP_DATA_ERROR: Cleartext HTTP traffic to 127.0.0.1 not permitted
08-09 10:50:34.402 30791 3607 D DownloadManager: [647] Finished with status WAITING_TO_RETRY

编辑:“修复”此问题后的更新(2018 年 8 月 21 日)似乎在安装应用程序几个小时后,DownloadManager 神秘地停止接受明文 HTTP。

我无法解释发生了什么。如果我重新启动设备一段时间后一切正常,那么 DownloadManager 会再次拒绝明文。我将此记为 Android P 错误,希望得到解决。

编辑 2:更新(2019 年 1 月 17 日)我的 pixel2 现在运行 android 9,补丁从 2019 年 1 月 5 日开始,我不再看到这个问题(到目前为止)。我猜自 8 月以来,这个问题已在某个补丁中得到解决。

最佳答案

创建 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 内的标记应用程序中引用此文件。喜欢:

android:networkSecurityConfig="@xml/network_security_config"

关于android - 如何解决 Android P DownloadManager 以 "Cleartext HTTP traffic to 127.0.0.1 not permitted"停止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51770323/

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