1

Is there a condition I could add to shouldOverrideUrlLoading that would keep some links in the app while directing others to the mobile browser?

My initial thoughts were something like this:

if (url.contains("myurl.com")){
    //open the url in the app
}
else{
    //open the url in the mobile browser
}

With my limited understanding this is the best idea I could come up with. I'm open to other ideas, and any syntax help would be greatly appreciated.

TreK
  • 1,144
  • 2
  • 13
  • 25

1 Answers1

2

your initital thoughts are correct.
in fact, I beleive shouldOverrideUrlLoading() is a part of the API for doing exactly that.

open the url in the app =

super.shouldOverrideUrlLoading();
mYourWebViewInstance.loadUrl(url);
return true;

open the url in the mobile browser =

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url ));
startActivity(browserIntent);
return true;

this code will launch directly app that can handle this data type, which be in this case any browser app installed on your device, or will give you intent chooser to select one of your browsers to show the url if you have more then one web browsers installed and none of them set to be default (always open with...)

returning true according to the documentation means you handled the url yourself, and the event is consumed.

there is also an issue of inconsistency across android platforms and certain firmwares - from my experience, I've seen that in some devices not overriding this callback will returns false by default (will trigger intent chooser for external web browser), and some devices returns true by default.

that's why you always have to override this callback, for making sure you know exactly how your app behaves on all devices.

so, is it answering your question or not?

Community
  • 1
  • 1
Tal Kanel
  • 10,475
  • 10
  • 60
  • 98
  • Thanks, I'll give this a try to see if it works for me or not. – TreK Aug 22 '13 at 16:59
  • Well, Kind of. There are real sporadic results. I'm trying to change my procedures around to see if I can solidify the results a little better. I will award you the answer because you sent me in the right direction. Thanks – TreK Aug 28 '13 at 17:28