WebView loadData () не работает Android 9.0 - PullRequest
0 голосов
/ 23 апреля 2019

Я пытаюсь загрузить уже извлеченные HTML-данные на уровне API 28 с loadData на WebView as-

Element content = doc.select("div.story-page-content").first();
                    String base64 = null;
                    String html="<font size=4px color=#000ff>" + source + "</font> | <font size=2px color=#ff0000>" + date + "</font><br>" + content.html();
                    base64 = android.util.Base64.encodeToString(html.getBytes("UTF-8"),
                            android.util.Base64.DEFAULT);


                mContent.loadData(base64, "text/html; charset=utf-8", "base64");

Приложение ничего не показывает.Я даже пробовал loadDataWithBaseUrl () as-

mContent.loadDataWithBaseURL(null,html, "text/html", "utf-8",null);

Все еще не помогло.Где я ошибаюсь?

ПРИМЕЧАНИЕ: - Я использую Jsoup для загрузки веб-контента.

РЕДАКТИРОВАТЬ: Спасибо за ваши ответы.Кстати, я как-то исправил это, удалив внешний LinearLayout, который содержал webView.Я не знаю, почему это происходит, но после API 28 webView внутри LinearLayout не работает.Вот мой файл макета -

<?xml version="1.0" encoding="utf-8"?>


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/webScroll"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"

    android:layout_height="match_parent">

    <TextView
        android:id="@+id/titleText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:layout_gravity="center_vertical"
        android:layout_margin="@dimen/dimen_8x"
        android:fontFamily="sans-serif-condensed"
        android:includeFontPadding="false"
        android:text="Sample Title"
        android:textColor="@color/defaultContentColor"
        android:textSize="@dimen/dimen_24x"
        android:textStyle="bold" />

    <ProgressBar
        android:id="@+id/webProgress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <ImageView
        android:id="@+id/mainImage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/titleText"
        app:srcCompat="@drawable/fastscroll__default_handle" />


        <WebView
            android:id="@+id/newsContent"
            android:layout_below="@id/mainImage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="40dp"
            android:layout_marginLeft="@dimen/dimen_8x"
            android:layout_marginRight="@dimen/dimen_8x"
            android:layout_marginTop="@dimen/dimen_4x"

            android:textSize="@dimen/fastscroll__bubble_corner" />




</RelativeLayout>

</ScrollView>

1 Ответ

0 голосов
/ 25 апреля 2019

Похоже, вы не получаете такой же ответ от сайта, как раньше. Это может быть заменено неверной строкой пользовательского агента с более новой версией Android, которую вы сейчас используете. Попробуйте добавить его в свой запрос:

Connection.Response loginForm = Jsoup.connect(myUrl)
    .method(Connection.Method.GET)
    .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0")
    .execute();

Вы можете найти строку пользовательского агента вашей предыдущей версии, запустив код из ответа Tofeeq здесь Как узнать строку пользовательского агента для конкретных устройств Android? и использовать ее вместо строка в моем коде.

...