如何解决Android P DownloadManager停止“明文HTTP流量到127.0.0.1不允许"的情况? [英] How to solve Android P DownloadManager stopping with "Cleartext HTTP traffic to 127.0.0.1 not permitted"?

查看:365
本文介绍了如何解决Android P DownloadManager停止“明文HTTP流量到127.0.0.1不允许"的情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经定义了一个自定义网络安全配置,并按照建议

I have already defined a custom network security config and included it in my manifest as recommended 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中看到了这一点:

Even with these changes when attempting to communicate via HTTP to 127.0.0.1 I see this in 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错误,希望可以解决.

更新(2019年1月17日),我的pixel2现在正在运行android 9,并带有2019年1月5日以来的补丁程序,到目前为止我再也没有看到这个问题.我猜这是从八月开始在某个补丁中解决的.

推荐答案

创建XML res/xml/network_security_config.xml

Create a 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中引用此文件.喜欢:

Reference this file in your tag Application, inside AndroidManifest.xml. Like:

android:networkSecurityConfig="@xml/network_security_config"

这篇关于如何解决Android P DownloadManager停止“明文HTTP流量到127.0.0.1不允许"的情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆