自己做的一个app小工具在android8.0上运行正常,9.0上就无法拉取数据,查看了9.0更新内容发现android P限制了明文流量的网络请求,非加密的流量请求都会被系统禁止掉。
解决方案:
新建资源文件,XXXX.xml;
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
manifest配置:
<application
android:networkSecurityConfig="@xml/XXXX">
<!--9.0加的-->
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
</application>
就这样就可以了;