Ajay
Ajay

Reputation: 1

HTTP Links Not Opening in Android WebView in Android Studio Java?

When I open a URL that Starts with "https://" in android WebView it works properly and Play a Video in video player from same type of URL ("https://") video also plays well. But whenever I tries to open non secure ("http://") URL WebView and Video Player both don't work. If you have any solution of this question then please answer ?

Upvotes: 0

Views: 1385

Answers (1)

hata
hata

Reputation: 12483

Starting with Android 9 (API level 28), cleartext support is disabled by default.

You need to set Manifest and res/xml/network_security_config.xml properly. Below example is for http://test.com:

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config"
                    ... >
        ...
    </application>
</manifest>

res/xml/network_security_config.xml:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="false" />
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">test.com</domain>
    </domain-config>
</network-security-config>

Upvotes: 1

Related Questions