Assuming you are accessing a server that doesn't support HTTPS, then you can create exceptions in your network security config.
You can create a file net_sec_conf.xml
like this:
<?xml version="1.0" encoding="utf-8" ?>
<network-security-config>
<base-config cleartextTrafficPermitted="false">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">api.example.org</domain>
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</domain-config>
</network-security-config>
and then in manifest file add this line:
android:networkSecurityConfig="@xml/net_sec_conf"
(assuming you have put the file in xml folder).
This way cleartext HTTP traffic will only be allowed for the specified domain.
Of course, if the server supports HTTPS, then you just need to change your URL "http://..." to "https://...".
usesCleartextTraffic
programmatically ? – Shunt