ERR_INVALID_RESPONSE при загрузке веб-просмотра в Android 9 - PullRequest
1 голос
/ 01 июля 2019

Мой код работает очень хорошо в Android ниже 9, но в Android 9 У меня проблема с WebView при загрузке ресурса, и он показывает мне сообщение об ошибке:

"Веб-страница недоступна Веб-страница с данными: text / html; charset = utf-8; charset = utf-8; base64, не может быть загружен, потому что: нетто :: ERR_INVALID_RESPONSE "

Я думаю, что проблема с UTF8 в Android 9. Я нахожу это:

В Android 9 декодер UTF-8 для языка Java более строг и соответствует стандарту Unicode.

в андроид-9.0-миграция 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); }

Ответы [ 2 ]

0 голосов
/ 02 июля 2019
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();
    }
0 голосов
/ 01 июля 2019
Actually you should avoid using http, but if there is no way you can do this:

Add @xml/network_security_config into your resources:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">www.smedk.ru</domain>
    </domain-config>
</network-security-config>
Add this security config to your Manifest like this:

<application
    ...
    android:networkSecurityConfig="@xml/network_security_config"
    ...>

    ...
</application>
Now you allowed using HTTP connection on www.smedk.ru subdomains.

You can read more in https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted

Note: The guidance in this section applies only to apps that target Android 8.1 (API level 27) or lower. Starting with Android 9 (API level 28), cleartext support is disabled by default.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...