Issue
Normally, when a link is clicked inside a WebView, an intent causes the web browser or another activity supporting that intent to open.
WebView webView = new WebView(this);
setContentView(webView);
webView.loadUrl("http://google.com");
However, when I merely set an empty WebViewClient…
WebView webView = new WebView(this);
webView.setWebViewClient(new WebViewClient() {});
setContentView(webView);
webView.loadUrl("http://google.com");
…links are opened within the WebView and no intents are fired! How come?
Solution
This is by design.
http://developer.android.com/guide/webapps/webview.html#HandlingNavigation
To open links clicked by the user, simply provide a
WebViewClient
for yourWebView
, usingsetWebViewClient()
. For example:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
That's it. Now all links the user clicks load in your WebView.
And
If WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the url. If WebViewClient is provided, return true means the host application handles the url, while return false means the current WebView handles the url
shouldOverrideUrlLoading
defaults to returning false
Answered By - Ken Wolf
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.