WebView is not opening google.com

浪尽此生 提交于 2020-01-06 15:03:13

问题


My webview is able to load both https & http sites But not https://www.google.com

It doesn't throw any error either.

Here is my code.I am unable to solve this problem

     super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final Button btn = (Button) findViewById(R.id.Button1);
        final EditText et=(EditText)findViewById(R.id.EditText1);
        final WebView wv1=(WebView)findViewById(R.id.WebView1);

        wv1.getSettings().setJavaScriptEnabled(true);
        wv1.getSettings().setDomStorageEnabled(true);
        wv1.setInitialScale(100);

        et.setFocusable(true);


        btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                 wv1.loadUrl(et.getText().toString());  
            }
        });

        wv1.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return true;
            }
ca
            public void onPageFinished(WebView view, String url) {
                Toast.makeText(getApplicationContext(),"Page Finished",Toast.LENGTH_LONG).show();
            }

            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();
            }
        });

        wv1.loadUrl("https://www.bing.com");

Thanks for any kind of help.


回答1:


There is a bug in your code

Your code

public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return true;
        }

Correct code

 public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }

ShouldOverrideUrlLoading should return false to open url in webview. True is for opening in some other app.



来源:https://stackoverflow.com/questions/28484286/webview-is-not-opening-google-com

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