Android Studio使用Webview 时 net::ERR_CLEARTEXT_NOT_PERMITTED解决办法

前言


Android Studio中使用webview加载URL出现net::ERR_CLEARTEXT_NOT_PERMITTED
cleartext为明文 permitted表示允许
即加载http时明文不被允许

从Android 9.0(API级别28)开始,默认情况下禁用明文支持。因此http的url均无法在webview中加载

因此需要添加允许权限

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:usesCleartextTraffic="true"    加上这句即可
    android:theme="@style/AppTheme">

如果是网络权限问题 加上

<uses-permission android:name="android.permission.INTERNET"/>

猜你喜欢

转载自blog.csdn.net/liyuanbo1997/article/details/105421684