2010-11-19 25 views

Respuesta

12

puede utilizar para este Intención:

Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("your Url")); 
startActivity(browserIntent); 
+8

debes usar Intent.ACTION_VIEW – rajh2504

151

que tenía que hacer la misma cosa hoy y me ha encontrado una respuesta muy útil en StackOverflow que quiero compartir aquí por si alguien más lo necesita.

Source (de sven)

webView.setWebViewClient(new WebViewClient(){ 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     if (url != null && (url.startsWith("http://") || url.startsWith("https://"))) { 
      view.getContext().startActivity(
       new Intent(Intent.ACTION_VIEW, Uri.parse(url))); 
      return true; 
     } else { 
      return false; 
     } 
    } 
}); 
+3

¡esta respuesta me ayudó mucho! ¡Gracias! –

+5

Tenga en cuenta que si la url es relativa, (no comienza con "http: //") se abrirá dentro de la aplicación. Para evitar esto, siempre se devuelve verdadero y los enlaces de URL relativos no hacen nada. –

+0

+1 respuesta realmente perfecta. :) –

5

Puede utilizar una intención para esto:

Uri uriUrl = Uri.parse("http://www.google.com/"); 
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl); 
startActivity(launchBrowser); 
25
WebView webview = (WebView) findViewById(R.id.webview); 
    webview.loadUrl(http://www.playbuzz.org); 

usted no tiene que incluir el código // webview.setWebViewClient (nueva WebViewClient()); lugar u necesidad de utilizar el código de abajo d

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; 
       } 
     } 
    }); 
+3

este código realmente me ayuda en ese problema – Cristiana214

7

Sólo tiene que añadir la siguiente línea

yourWebViewName.setWebViewClient(new WebViewClient()); 

Comprobar this para la documentación oficial.

Cuestiones relacionadas