大清早被业务群@了,线上App遇到了问题: 提示:net::ERR_CLEARTEXT_NOT_PERMITTED
之前都是没问题的,又是什么问题呢?应该猜到是Android SDK升级造成的没错了,Stackoverflow看看,果不其然。
从Android 9.0(API级别28)开始,默认情况下限制了明文流量的网络请求,对未加密流量不再信任,直接放弃请求,因此http的url均无法在webview中加载,https 不受影响。
解锁正确姿势
首先保证App申明了网络权限
<uses-permission android:name="android.permission.INTERNET" />
解决办法(1):
在Application中打开一个开关
<manifest ...>
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>
完整AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.wuzhao.mybrower">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:targetApi="m">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<!-- 添加网络权限 -->
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
原文链接
https://blog.csdn.net/geofferysun/article/details/88575504