Issue
Previously when using a webview in android, clicking any link would force the "proper" browser to open and then web browsing would continue in that instance.
However this seems to no longer be the case. The following code results in all links staying inside the webview, but I actually want the links to launch a new browser instance. Did this change in 2.3 ?
Note I am asking the opposite of what most people ask (they ask how to keep all links inside the webview, I want them to launch outside)
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView view = new WebView(this);
setContentView(view);
view.loadUrl("http://news.bbc.co.uk");
}
}
EDIT: Clarification - the first URL will load in the WebView and all subsequent clicks will open in a new browser. This is simplification from what I really want, but good enough.
Bascially the problem is, previously clicking a link would open a new browser session. Most people don't want that (hence the questions on here about it) but I do. However for some reason now it seems to load in the webview all the time (2.3 perhaps?)
Solution
Let me understand. Do you want to launch the first webpage in the same webview, while the other hyperlinks to go to the default browser, or you want the default browser itself to open for the first link clicked?
If it's the first case, I don't exactly know, unless you know some way to gather the link URL from the webview.
For the second instance, i.e. launching the default browser for any URL click, just skip (remove) this line: view.setWebViewClient(new WebViewClient() { });
, which will open all the links in the default browser, and not the webview itself.
Answered By - SamSPICA
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.