繁体   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