美文网首页
Android6.0~9.0系统适配

Android6.0~9.0系统适配

作者: GexYY | 来源:发表于2018-11-23 14:57 被阅读0次

9.0系统问题 :

  • http明文网络请求问题
    Android P 限制了明文流量的网络请求,非加密的流量请求都会被系统禁止掉.
    CLEARTEXT communication to life.115.com not permitted by network security policy
  • 解决方法:
    在资源文件新建xml目录,新建文件network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
      <base-config cleartextTrafficPermitted="true">
             <trust-anchors>
                  <certificates src="system" overridePins="true" />
                  <certificates src="user" overridePins="true" />
             </trust-anchors>
       </base-config>
</network-security-config>

在清单配置文件中如下配置:

<application
        android:networkSecurityConfig="@xml/network_security_config">
        <!--9.0加的,哦哦-->
        <uses-library
            android:name="org.apache.http.legacy"
            android:required="false" />
</application>

最后还是建议都用https请求:

原文链接: https://juejin.im/post/5beaf27fe51d45332a4568e9

相关文章

网友评论

      本文标题:Android6.0~9.0系统适配

      本文链接:https://www.haomeiwen.com/subject/coyjqqtx.html