user677767
user677767

Reputation: 203

API 29 webview net::ERR_CLEARTEXT_NOT_PERMITTED

In my webview I load an html, which is a string, as follows:

myWebView.loadData(htmlTemplate, "text/html", "utf-8");

This displays a certain content, where there is a button. In the click of the button, a url is supposed to be loaded:

http://10.5.6.13:9090/

But it fails with error net::ERR_CLEARTEXT_NOT_PERMITTED

I have already tried all the popular suggested answers that suggest to add:

android:usesCleartextTraffic="true"

or override networkSecurityConfig:

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

This is the list of the already tried answers:

https://stackoverflow.com/a/52708032/12202026

https://stackoverflow.com/a/53387018/12202026

http://android--kotlin.blogspot.com/2019/03/android-webview-neterrcleartextnotpermi.html

And many popular other answers out there, but still nothing.

Upvotes: 2

Views: 1050

Answers (1)

mewadaarvind
mewadaarvind

Reputation: 399

Create file - res folder then xml folder then set network_security.xml
res/xml/network_security.xml

In **network_security.xml** ->

**soluction number 1:** 
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">192.168.0.101</domain>
    </domain-config>
</network-security-config>

**soluction number 2:** 
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">api.example.com(to be adjusted)</domain>
    </domain-config>
</network-security-config>

**soluction number 3:** 
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
            <certificates src="user" />
        </trust-anchors>
    </base-config>
</network-security-config>

Upvotes: 0

Related Questions