[英]Android Webview page could not be loaded with HTTP hyperlink because ERR_CLEARTEXT_NOT_PERMITTED
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.我正在开发一个 android 本机应用程序,我正在从 strings.xml 在 WebView 中加载一个 HTML 字符串,其中包含一些超链接文本。 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
.所有这些中的一个超链接是
http
url 并且它没有在 webView 中打开并抛出错误为ERR_CLEARTEXT_NOT_PERMITTED
。 I'm already using usesCleartextTraffic
settings in my app but still unable to use that.我已经在我的应用程序中使用了
usesCleartextTraffic
设置,但仍然无法使用它。
AndroidManifest.xml 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 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 UIClass.kt
//Enabling JS for allowing all hyperlinks
binding.webView.settings.javaScriptEnabled = true
binding.webView.settings.javaScriptCanOpenWindowsAutomatically = true
build.gradle构建.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我从
AndroidManifest.xml
文件中删除了一行
android:networkSecurityConfig="@xml/network_security_config"
and it worked for me.它对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.