错误 网络请求时

// Android P系统限制了明文流量的网络请求 就会报这个错误
CLEARTEXT communication to xxx.xxx   not permitted by network security policy
解决方法
  1. res目录下新建一个xml文件夹
  2. 新建 network_config.xml
<?xml version ="1.0" encoding ="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>
  1. 添加到application中
<application
        android:name=".MyApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:hardwareAccelerated="false"
        android:configChanges="touchscreen"
        android:networkSecurityConfig="@xml/network_config"
        android:theme="@style/AppTheme">
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐