做了一个简单的http登录的APP,在老手机上可以允许,但是在新手机android10上却不可以。怀疑是高版本安卓废弃了部分代码,但是我只是简单的HttpURLConnection啊?百度搜一搜,发现是android9以上不能http通信,再百度下,找到一个解决办法。
再res下新建一个xml,如http.xml.我是android stuio中选择res新建xml->选择app action xml,自动生成了一个xml目录,然后修改xml文件
<?xml version ="1.0" encoding ="utf-8"?>
<!--允许使用http-->
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
最后修改AndroidManifest.xml,在application中添加android:networkSecurityConfig="@xml/http"
<application
android:allowBackup="true"
android:networkSecurityConfig="@xml/http"
android:icon="@mipmap/ic_launcher"
...