Tuesday, November 26, 2019

Cleartext HTTP traffic not permitted Android Studio

Cleartext HTTP traffic not permitted

Solution #1: Use HTTPS instead of HTTP

Using encrypted transfer protocol is the recommended way of communication between android applications and servers. It means that you should configure the server to use encrypted traffic. How? It depends on what exactly server do you use, but just google “server name https configuration”

Solution #2:

Create file res/xml/network_security_config.xml -
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">domain.com or IP (to be adjusted)</domain>
    </domain-config>
</network-security-config>
AndroidManifest.xml -
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:networkSecurityConfig="@xml/network_security_config"
        ...>
        ...
    </application>
</manifest>

No comments:

Post a Comment