java.net.UnknownServiceException: CLEARTEXT communication to xxxxx not permitted by network

Preface: In order to ensure the security of user data and devices, Google will require encrypted connections by default for the next-generation Android system (Android P) applications, which means that Android P will prohibit apps from using all unencrypted connections, so it runs Android No matter whether the Android devices of the P system receive or send traffic, they will not be able to transmit in clear code in the future. They need to use the next-generation (Transport Layer Security) transport layer security protocol, while Android Nougat and Oreo are not affected.
 

In the new features of Android 9.0 system, all applications use HTTPS, which means that Google prohibits clear text transmission in order to ensure the security of the APP. If you have to run this APP on a 9.0 system device, there are the following solutions:
Method 1:

Change http transmission to https transmission

Method Two:

By configuring XML to bypass HTTP restrictions

The complete solution steps for the first solution in the above conclusion are given below:

First create an xml directory under the res folder, create a new network_security_config.xml file, and generate the following code:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

Then do the following configuration in the Application of AndroidManifest.xml:

android:networkSecurityConfig="@xml/network_security_config"

Through the above analysis, it should be possible to roughly understand the principle of such a configuration.

In addition, using Volley also needs to configure the following code in the application:

 <uses-library android:name="org.apache.http.legacy" android:required="false" />


Method three:

Change targetSdkVersion to 27 or less (including 27)
 

 

The best guide for Android 10.0 adaptation:

https://mp.weixin.qq.com/s/dkZHGZproqAdEifpyyjuNw

Source code analysis Android 9.0 http request adaptation principle:

https://www.jianshu.com/p/79f573bd0938

 

 

 

 

Guess you like

Origin blog.csdn.net/MYBOYER/article/details/102663323