简体   繁体   English

Android Webview不会加载特定网址的内容

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

Android web-view (api 28) does not load content for specific this url. Android网络视图(api 28)不会为此特定网址加载内容。 Do i need to add any specific permission for it ? 我需要为其添加任何特定权限吗?

        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" />

That web page is loading the content using js script inside the div tag using javascript and has google map api code. 该网页使用javascript在div标签中使用js脚本加载内容,并具有google map api代码。

Update It was Domstorage issue. 更新这是Domstorage问题。

webview.getSettings().setDomStorageEnabled(true);

Try this, it works for me 试试这个,对我有用

xml-- 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-- 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);

Your code is perfectly working on my mobile. 您的代码可以在我的手机上完美运行。 Here is my code. 这是我的代码。 From Main Activity you go to WebActvity. 从主要活动中,转到WebActvity。

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

In WebviewActivity - 在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"
    />

Here is the java code for WebViewActivity. 这是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());

Make sure, you are connected to the internet and not having any other issues. 确保您已连接到互联网并且没有任何其他问题。 Still, you can get the suggestion from dharms and go through the documentation . 不过,您仍然可以从dharms那里获得建议并浏览文档
Another thing - make sure your webview has enough space for loading the contents. 另一件事-确保您的Web视图有足够的空间来加载内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM