Web View not working with some specific url

2019-07-27 08:44发布

问题:

public class MainActivity extends AppCompatActivity {

    String url = "https://www.pinterest.com";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView webView = findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.setWebViewClient(new WebViewClient(){

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);

                return true;
            }
            @Override
            public void onPageFinished(WebView view, final String url) {
            }
        });

        webView.loadUrl(url);       
    }
}

Web View is not loading "https://www.pinterest.com" within the application but it was working with chrome browser using intent. I tried of other urls it's working. While loading "https://www.pinterest.com" using webview, getting the output screen like below

回答1:

You try this:

WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAllowContentAccess(true);
settings.setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://www.pinterest.com/");

In manifest:

android:hardwareAccelerated="true"


回答2:

set the JavascriptEnabled and AllowContentAccess and setDomStorageEnabled to true in settings