解决CLEARTEXT communication to XXX not permitted by network security

Posted 听♞海

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决CLEARTEXT communication to XXX not permitted by network security相关的知识,希望对你有一定的参考价值。

解决方案一:

androidManifest.xml文件下的application标签中加入以下属性:
android:usesCleartextTraffic=“true”

解决方案二:

我们先在这里复习一下资源的使用吧

res子目录可以存放的资源
res/anim定义补间动画的XML文件
res/color定义不同状态下颜色列表的XML文件
res/drawable各种位图文件(png、jpg、gif、9-Patch)可以编译成各种drawable对象的XML文件
res/mipmap应用程序Launcher图标
res/layout用户界面布局文件
res/menu菜单资源布局文件(选择菜单、子菜单、上下文菜单)
res/raw任意类型的原生资源
res/values各种简单值的XML文件(包括字符串、整数、数组、尺寸等)
res/xml其他任意的XML文件(可能没有特殊意义的XML文件)

所以我们就在res目录下新建xml文件夹,创建一个XML文件,名为network_security_config.xml,如图:

<?xml version ="1.0" encoding ="utf-8"?><!--  Learn More about how to use App Actions: https://developer.android.com/guide/actions/index.html -->
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

接下来在AndroidManifest.xml文件下的application标签中添加配置:
android:networkSecurityConfig="@xml/network_security_config"
就可以了。

以上是关于解决CLEARTEXT communication to XXX not permitted by network security的主要内容,如果未能解决你的问题,请参考以下文章

android 关于CLEARTEXT communication to xxx.xxx not permitted by network security policy错误

android 关于CLEARTEXT communication to xxx.xxx not permitted by network security policy错误

java.net.UnknownServiceException: CLEARTEXT communication to www.httpbin.org not permitted by networ

Android P系统的设备上 java.net.UnknownServiceException: CLEARTEXT communication to XXXXXXX not permitted

Cleartext HTTP traffic to xxx not permitted解决办法

Cleartext HTTP traffic to xxx not permitted解决办法