简体   繁体   中英

Android webview does not load content for specific url

Android web-view (api 28) does not load content for specific this url. 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.

Update It was Domstorage issue.

webview.getSettings().setDomStorageEnabled(true);

Try this, it works for me

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

Your code is perfectly working on my mobile. Here is my code. From Main Activity you go to WebActvity.

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

In 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.

 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 .
Another thing - make sure your webview has enough space for loading the contents.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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