WebView链接单击打开默认浏览器

现在我有一个加载webview的应用程序,所有点击都保存在应用程序中。我想要做的是当某个链接,例如,在应用程序中单击http://www.google.com时,它会打开默认浏览器。如果有人有想法请告诉我!     
已邀请:
今天我必须做同样的事情,我在StackOverflow上找到了一个非常有用的答案,我想在这里分享以防其他人需要它。 来源(来自斯文)
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;
        }
    }
});
    
WebView webview = (WebView) findViewById(R.id.webview);
webview.loadUrl(https://whatoplay.com/);
你不必包含这段代码
// webview.setWebViewClient(new WebViewClient());
相反,你需要使用下面的代码
webview.setWebViewClient(new WebViewClient()
{
  public boolean shouldOverrideUrlLoading(WebView view, String url)
  {
    String url2="https://whatoplay.com/";
     // 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;
    }
  }
});
    
你可以使用Intent:
Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("your Url"));
startActivity(browserIntent);
    
您只需添加以下行
yourWebViewName.setWebViewClient(new WebViewClient());
请查看此官方文档。     
您可以使用Intent:
Uri uriUrl = Uri.parse("http://www.google.com/"); 
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);  
startActivity(launchBrowser);  
    

要回复问题请先登录注册