简体   繁体   中英

Webview not opening link in Android?

I am trying to open any link, like facebook.com for instance, but the link is not opening. What am I missing?

MainActivity:

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);

        WebView webview= (WebView) findViewById(R.id.webID);
        webview.loadUrl("https://www.facebook.com/");
        webview.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int progress) {
                if (progress == 100) {
                    progressDialog.dismiss();                                    
                }
            }
        });
    }

Add, in onCreate , after your webview declaration:

webview.setWebViewClient(new WebViewClient());

You may need to enable JavaScript depending on what else you need to do. For that use:

webview.getSettings().setJavaScriptEnabled(true);

And do not forget to add:

<uses-permission android:name="android.permission.INTERNET"/>

In your manifest.

enable javascript:

webview.getSettings().setLoadsImagesAutomatically(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("https://www.facebook.com/");

more info here

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