android不予许明文http通讯_如何解决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:

127.0.0.1

localhost

and this is in my Android.manifest:

android:allowBackup="false"

android:usesCleartextTraffic="true"

android:networkSecurityConfig="@xml/network_security_config"

android:label="@string/app_name"

android:theme="@style/AppTheme"

android:persistent="true" >

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

EDIT: Update (21 Aug 2018) after "fixing" this issue it seems that a couple of hours after the app is installed the DownloadManager mysteriously stops accepting cleartext HTTP.

I can't explain what's happening. If I reboot the device things work great for a period of time then DownloadManager refuses cleartext again. I'm writing this off as an Android P bug that I hope gets resolved.

EDIT 2: Update (17 Jan 2019) my pixel2 is now running android 9 with a patch from 5 Jan 2019 and I no longer see the issue (so far). I'm guessing this got resolved in some patch since August.

解决方案

Create a XML res/xml/network_security_config.xml

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

android:networkSecurityConfig="@xml/network_security_config"

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值