0

I am using webview to load URL in my application.

This is code of file related to webview in XML

 <WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/login_button" />

Java File

WebView twitterSite = (WebView)findViewById(R.id.webView1);           

twitterSite.getSettings().setJavaScriptEnabled(true);

twitterSite.loadUrl("http://www.google.com");

When I do this it doesn't open google in webview rather it asks to select action using Browser or chrome.

What could be the problem in this ? Because this is as simple as it could be.

keen
  • 3,001
  • 4
  • 34
  • 59

1 Answers1

0

I just came to know that I forgot to implement webViewClient and it's method.

I added this before to loadUrl line to make it work.

    twitterSite.setWebViewClient(new Callback());

and this.

private class Callback extends WebViewClient{   

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

}

Thanks to this.

Community
  • 1
  • 1
keen
  • 3,001
  • 4
  • 34
  • 59