Android studio使用webview控件加載非https鏈接時報錯原因及解決辦法
時間:2021年12月15日
瀏覽:次
提示如下內(nèi)容:
Android WebView net::ERR_CLEARTEXT_NOT_PERMITTED
解決方法:
一、問題描述
在Android中使用WebView加載非https鏈接時,出現(xiàn)錯誤:
net::ERR_CLEARTEXT_NOT_PERMITTED
二、原因分析
從Android 9.0(API級別28)開始,默認(rèn)情況下禁用明文支持。因此http的url均無法在webview中加載,Android9.0對未加密的流量不再信任,添加了新的限制。
三、解決辦法
1.創(chuàng)建文件 res/xml/network_security_config.xml
其中將m.boomerlogic.com替換為你自己的域名,根域名即可,includeSubdomains="true" 就包含了二級域名。
2.修改 AndroidManifest.xml
添加網(wǎng)絡(luò)訪問權(quán)限:
引入配置文件:
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"