Я использую этот код ниже
Шаг 1: создайте папку xml в папке res в проекте Android
Шаг 2 создайте один файл в папке xml, как показано ниже:
#
имя файла: network_security_config.xml
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
#
Шаг 3 в AndroidManifest.xml
< application
android:name=".ExampleApplication"
android:networkSecurityConfig="@xml/network_security_config"
android:allowBackup="false"
tools:replace="android:allowBackup"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">