mejkan mejkan - 5 months ago 14
Android Question

webview not openning link in android?

i am trying to open any link like "

facebook.com
" but not opening. please tell me what i am missing . this is the main activity class code.

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


}

Answer

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.

Comments