gpt4 book ai didi

java - 在 android 9 中加载 webView 时出现 ERR_INVALID_RESPONSE

转载 作者:行者123 更新时间:2023-12-01 06:01:42 25 4
gpt4 key购买 nike

我的代码在 android 9 以下运行得很好,但在 android 9 中,我在加载资源时遇到 webView 问题,它向我显示错误消息:

“网页不可用网页位于 data:text/html; charset=utf-8;charset=utf-8;base64,无法加载,因为:net::ERR_INVALID_RESPONSE"

我认为问题出在 android 9 中的 UTF8 上。我发现这个:

In Android 9, the UTF-8 decoder for Java language is stricter and follows the Unicode standard.

在 android-9.0-migration https://developer.android.com/about/versions/pie/android-9.0-migration

我的代码是:

public void loadResourcePage() {
loadDataWithBaseURL(basePath, "<html><body><p> some text </p></body></html>", "text/html", "UTF-8", null); }

最佳答案

The documents at this page (https://developer.android.com/about/versions/pie/android-9.0-migration) mention that:

In Android 9, the UTF-8 decoder for Java language is stricter and follows the Unicode standard.

So try converting the UTF-8 into Base64 and use loadData()

try {
String base64 = null;
base64 = android.util.Base64.encodeToString(lecureHtmlData.getBytes("UTF-8"),
android.util.Base64.DEFAULT);
wvLecture.loadData(base64, "text/html; charset=utf-8", "base64");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}

关于java - 在 android 9 中加载 webView 时出现 ERR_INVALID_RESPONSE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56832101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com