mejkan
mejkan

Reputation: 87

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();                                    
                }
            }
        });
    }

Upvotes: 0

Views: 91

Answers (2)

Daniel
Daniel

Reputation: 2373

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.

Upvotes: 1

Reza Nazeri
Reza Nazeri

Reputation: 315

enable javascript:

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

more info here

Upvotes: 0

Related Questions