Issue
I am showing a website into an Android webView. So, I wrote an override to make the links open inside the webView instead of the default browser. My problem is that I have some specific links in my site that I want to open, just these, in the default browser. How can I create an override inside that override? The code that I´m using was supposed to work, but it doesn´t.
public class MyAppWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("something.com")) {
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
return true;
}
Solution
I´ve found a solution. I just used this code:
myWebView.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
String url2="http://www.example.com/";
// all links with in your site will be open inside the webview
//links that start your domain, for example (http://www.example.com/)
if (url != null && url.startsWith(url2)){
return false;
}
// all links that points outside the site will be open in a normal android browser
else {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}
}
});
Answered By - Semmerket
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.