delight-im / Android-AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box
MIT License
2.39k stars 574 forks source link

how to override shouldOverrideUrlLoading to limit webView to single domain? #59

Closed Mohammad699 closed 8 years ago

Mohammad699 commented 8 years ago

Hi, In the default webView we can override shouldOverrideUrlLoading like this

` @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (Uri.parse(url).getHost().endsWith("doblist.com")) { return false; }

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    view.getContext().startActivity(intent);
    return true;
}

`

to open external links in the default browser. I tried this with addPermittedHostname{"my-site.com") but it handles my site's sub folders as external links. it opens my-site.com/forum in a new tab or browser. How to solve this?

ocram commented 8 years ago

Thanks for your report!

Can you try

compile 'com.github.delight-im:Android-AdvancedWebView:2bd3e0534c36c5c046e5af6c039ce35eeb2addfb'

instead of

compile 'com.github.delight-im:Android-AdvancedWebView:v2.1.0'

please? Does this help?

Mohammad699 commented 8 years ago

@mwaclawek This solved the problem but is it save to use this version and publish the app on the store?

ocram commented 8 years ago

Thanks, great to hear that it works!

Yes, that should be safe. Nevertheless, there's now a new release that you can use:

compile 'com.github.delight-im:Android-AdvancedWebView:v2.1.1'

By the way, once you compiled your app and created the APK, it's always safe. At that point, the dependency is "baked in" to your app.

DanieLopez10 commented 5 years ago

Disculpa cual fue el codigo que utilizaste me pasa lo mismo (se nota que soy nuevo como puedo saber a que se refieren con: compile 'com.github.delight-im:Android-AdvancedWebView:v2.1.1' ?)

ocram commented 5 years ago

Just follow the README and use the latest version of this library, or at least v2.1.1.