簡體   English   中英

Android Webview不會加載特定網址的內容

[英]Android webview does not load content for specific url

Android網絡視圖(api 28)不會為此特定網址加載內容。 我需要為其添加任何特定權限嗎?

        WebView webview = (WebView)findViewById(R.id.webview1);
        webview.loadUrl(GlobalVariable.websiteUrl);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setGeolocationEnabled(true);
        //webview.setWebViewClient(new WebViewClientExtend(this));
        webview.setWebChromeClient(new WebChromeClient());

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

<WebView
    android:id="@+id/webview1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="0dp" />

該網頁使用javascript在div標簽中使用js腳本加載內容,並具有google map api代碼。

更新這是Domstorage問題。

webview.getSettings().setDomStorageEnabled(true);

試試這個,對我有用

xml--

<WebView
    android:id="@+id/web_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:layout_marginTop="@dimen/margin_10"
    android:layout_marginRight="3dp"
    android:layout_marginLeft="3dp">

java--

    WebView webview=dialog.findViewById(R.id.web_view);
    webview.loadUrl("Pass your url");
    final WebSettings webSettings = webview.getSettings();
    webSettings.setTextSize(WebSettings.TextSize.SMALLER);
    webview.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    webSettings.setGeolocationEnabled(false);

您的代碼可以在我的手機上完美運行。 這是我的代碼。 從主要活動中,轉到WebActvity。

webviewButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent=new Intent(context,WebviewActivity.class);
            startActivity(intent);
        }
    });

在WebviewActivity中-

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activity.WebviewActivity"
tools:showIn="@layout/activity_webview">

<WebView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/view_web"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="0dp"
    />

這是WebViewActivity的Java代碼。

 webView=(WebView)findViewById(R.id.view_web);
 webView.loadUrl("https://www.google.com/");
 webView.getSettings().setJavaScriptEnabled(true);
 webView.getSettings().setGeolocationEnabled(true);
 //webview.setWebViewClient(new WebViewClientExtend(this));
 webView.setWebChromeClient(new WebChromeClient());

確保您已連接到互聯網並且沒有任何其他問題。 不過,您仍然可以從dharms那里獲得建議並瀏覽文檔
另一件事-確保您的Web視圖有足夠的空間來加載內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM