WebView Links not opening

穿精又带淫゛_ 提交于 2020-01-23 12:11:34

问题


I am trying to open a link using Webview in Android. There are some links embedded into WebView. My problem is webview is not opening any link that does not starts with www. For ex, www.google.com is working but maps.google.com is not.I have also tried to override WebViewClient but it didn't work. One thing I noticed is by putting Toast to see what url is being called in WebViewClient. It showed perfect for www.google.com but returned nothing for other links. I thing WebViewClient is not getting overriden in that case. What could be the reason. Do I have to call any ethod or some property of webview. Any help will be appreciated.

menuView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            super.shouldOverrideUrlLoading(view, url);
            Toast.makeText(getApplicationContext(), "url:--" + url, Toast.LENGTH_LONG).show();          
            view.loadUrl(url);
            return false;
    }

    });

Properties that I have already set are :

menuView.setVerticalScrollBarEnabled(false);

    menuView.setHorizontalScrollBarEnabled(false);

    final WebSettings webSettings = menuView.getSettings();
    menuView.getSettings().setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setSupportMultipleWindows(true);

    webSettings.setPluginState(PluginState.ON);
    webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

    menuView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    menuView.getSettings().setBuiltInZoomControls(true);
    // Below required for geolocation
    menuView.getSettings().setJavaScriptEnabled(true);
    menuView.getSettings().setGeolocationEnabled(true);

    webSettings.setGeolocationEnabled(true);

    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);

回答1:


// in oncreate 
webview.setWebChromeClient(new wecrome());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadsImagesAutomatically(true);
webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webview.setWebViewClient(new MyBrowser());
webview.getSettings().setPluginState(PluginState.ON);
webview.loadUrl("http://www.example.net/locations/");

//inner class 
private class MyBrowser extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            view.addJavascriptInterface(new Object() {
                @JavascriptInterface
                public void performClick() throws Exception {
                    Log.d("LOGIN::", "Clicked");
                    Toast.makeText(googleplus.this, "Login clicked",
                            Toast.LENGTH_LONG).show();
                }
            }, "login");
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub

            System.out.println("started");
            pd.show();
            super.onPageStarted(view, url, favicon);

        }

        @Override
        public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            pd.dismiss();
            System.out.println("ends");
            super.onPageFinished(view, url);

        }

    }


来源:https://stackoverflow.com/questions/34266177/webview-links-not-opening

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