Google为了保证用户数据和设备安全,针对Android 系统(Android P) 的应用程序,将要求默认使用加密连接。Android P 将禁止 App 使用所有未加密的连接,因此运行 Android P 系统的安卓设备无论是接收或者发送流量,未来都不能明码传输。
因此在Android P 使用http请求会出现以下异常:
CLEARTEXT communication to xxx.xxx.xxx.xx not permitted by network security policy
解决的办法有2种
1.把所有的http请求全部改为https请求
2.在res的xml目录(),然后创建一个名为:network_config.xml文件
在文件中设置cleartextTrafficPermitted为开启状态
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
并在AndroidManifest.xml中配置cleartextTrafficPermitted
<application
****
android:networkSecurityConfig="@xml/network_config"
****
>