Webview loadurl crashing

妖精的绣舞 提交于 2019-12-05 13:49:19

You're likely running into the same problem as here.

When links are loaded in Android, by default the system will try to launch an application to handle the URL, in this case a browser. However Android Things does not include a browser by default, so it fails to handle the URL and crashes.

You can override this default behavior and have the URLs load in your app's WebView, by setting the WebViewClient in your app before loading any URLs:

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());

This is documented here.

If you have a web view along with a progress bar, then the code is down below:

WebView myWebView = (WebView) findViewById(R.id.webView3);

        progressDialog = new ProgressDialog(YOUR_ACTIVITY.this);
        progressDialog.setCancelable(true);
        progressDialog.setMessage("Please wait....");
        progressDialog.show();

        myWebView.setWebViewClient(new WebViewClient() {   // setting Progress Bar
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                Log.d(TAG, "LOADING");
                return true;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
            }

        });

        myWebView.setInitialScale(1);
        myWebView.getSettings().setLoadWithOverviewMode(true);
        myWebView.getSettings().setUseWideViewPort(true);
        myWebView.getSettings().setJavaScriptEnabled(true);myWebView.loadUrl("https://www.google.com");

        myWebView.getSettings().setSupportZoom(true);
        myWebView.getSettings().setBuiltInZoomControls(true);
        myWebView.getSettings().setDisplayZoomControls(false);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!