I'm working on an android native app where I'm loading a HTML string in WebView from strings.xml which has some hyperlink texts all. One hyperlink out of all of them is having http
url and which is not getting opened within webView and throwing error as ERR_CLEARTEXT_NOT_PERMITTED
. I'm already using usesCleartextTraffic
settings in my app but still unable to use that.
AndroidManifest.xml
<application
android:name=".com.app"
android:allowBackup="false"
android:icon="@mipmap/ic_hp_launcher"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_hp_launcher_round"
android:supportsRtl="false"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<debug-overrides>
<trust-anchors>
<!-- Trust user added CAs while debuggable only -->
<certificates src="user" />
<certificates src="system" />
</trust-anchors>
</debug-overrides>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
<domain-config cleartextTrafficPermitted="true">
<!-- Make sure your URL Server here -->
<domain includeSubdomains="true">https://xxxxxx.base.url</domain>
<domain includeSubdomains="true">http://.xxxx.org</domain>
<trust-anchors>
<certificates src="user"/>
<certificates src="system"/>
</trust-anchors>
</domain-config>
UIClass.kt
//Enabling JS for allowing all hyperlinks
binding.webView.settings.javaScriptEnabled = true
binding.webView.settings.javaScriptCanOpenWindowsAutomatically = true
build.gradle
minSdkVersion 28
targetSdkVersion 30
Please let me know if I'm doing any mistake. Thanks in advance.
I removed one line from the AndroidManifest.xml
file
android:networkSecurityConfig="@xml/network_security_config"
and it worked for me.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.