Skip to content Skip to sidebar Skip to footer

How Can I Load A Link In Other Browser From Web View?

I am loading string value in my web view and i need when i click on the link shown in web view should open in other web browser of phone. I want like this - String s = 'hello read

Solution 1:

Try this:

webView.setWebViewClient(newWebViewClient(){
publicbooleanshouldOverrideUrlLoading(WebView view, String url) {
    if (url != null && (url.startsWith("http://") || url.startsWith("https://"))) {
        view.getContext().startActivity(
            newIntent(Intent.ACTION_VIEW, Uri.parse(url)));
        returntrue;
    } else {
        returnfalse;
    }
}

});

Solution 2:

You can do something like this:

String s = "<ahref='http://www.google.com'target='_blank'>Read more over here</a>";
webview.loaddata(s);

You will need to add other html content by yourself.

So basically, you can use target='_blank' which will open it in a new browser, not in webview.

Hope it helps.

Post a Comment for "How Can I Load A Link In Other Browser From Web View?"