Skip to content

Instantly share code, notes, and snippets.

@ankittyagii
Created December 27, 2019 14:12
Show Gist options
  • Save ankittyagii/2f1b541ae88fc54bc1969afa1ba45e1b to your computer and use it in GitHub Desktop.
Save ankittyagii/2f1b541ae88fc54bc1969afa1ba45e1b to your computer and use it in GitHub Desktop.
How to enable Cleartext in Android
Solution 1. Open AndroidManifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>
Solution 2.
a. Create new file network_security_config.xml in res/xml/ folder.
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">your.domain.com</domain>
</domain-config>
</network-security-config>
b. Add the network_security_config.xml in AndroidManifest
<application
android:name="...."
android:networkSecurityConfig="@xml/network_security_config"
... />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment