À l'heure actuelle, j'ai une application qui charge une vue Web et tous les clics sont conservés dans l'application. Ce que je voudrais faire, c'est lorsqu'un clic sur un lien, par exemple, http://www.google.com , dans l'application ouvre le navigateur par défaut. Si quelqu'un a des idées s'il vous plaît faites le moi savoir!
Réponses
Trop de publicités?
Amokrane Chentir
Points
11441
Je devais faire la même chose aujourd'hui et j'ai trouvé une réponse très utile sur StackOverflow que je voudrais partager ici au cas où quelqu'un d'autre en aurait besoin.
webView.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.startsWith("http://")) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
});
Cristiana214
Points
661
WebView webview = (WebView) findViewById(R.id.webview);
webview.loadUrl(http://www.playbuzz.org);
vous n'avez pas à inclure ce code // webview.setWebViewClient (nouveau WebViewClient ()); à la place, vous devez utiliser le code d ci-dessous
webview.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
String url2="http://www.playbuzz.org/";
// all links with in ur site will be open inside the webview
//links that start ur domain 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;
}
}
});
PAD
Points
766
BasavRaj
Points
11