Issue
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.
Solution
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?
Answered By - Tal Kanel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.