在与Android的WebView浏览器中打开外部链接 [英] Open external links in the browser with android webview

查看:1230
本文介绍了在与Android的WebView浏览器中打开外部链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个code,但不是因为它的工作原理,它不断开放的WebView什么,我想要的是链接不属于我的网站在默认浏览器打开。任何想法?谢谢

 私有类CustomWebViewClient扩展WebViewClient {
        @覆盖
            公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
              如果(url.contains(message2space.es.vu)){
                view.loadUrl(URL);
                返回true;
            }其他{
                返回super.shouldOverrideUrlLoading(查看,网址);
            }

            }
        }
 

解决方案

现在的问题是,你需要发送的意图到默认的Web浏览器打开链接。你在做什么只是调用你的web视图处理的链接不同的方法。每当你想另一个应用程序来处理的东西你需要使用意图。试试这个code来代替。

 私有类CustomWebViewClient扩展WebViewClient {
        @覆盖
            公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
              如果(url.contains(message2space.es.vu)){
                view.loadUrl(URL);
              } 其他 {
                意图I =新的意图(Intent.ACTION_VIEW,Uri.parse(URL));
                startActivity(ⅰ);
              }
              返回true;
            }
        }
 

I have this code, but not because it works, it keeps opening in webview and what I want is that the links do not belong to my website open in your default browser. Any idea? thanks

private class CustomWebViewClient extends WebViewClient {
        @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
              if(url.contains("message2space.es.vu")){
                view.loadUrl(url);
                return true;
            }else{
                return super.shouldOverrideUrlLoading(view, url);
            }

            }
        }

解决方案

The problem is you need to send an Intent to the default web browser to open the link. What you are doing is just calling a different method in your Webview to handle the link. Whenever you want another app to handle something you need to use Intents. Try this code instead.

private class CustomWebViewClient extends WebViewClient {
        @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
              if(url.contains("message2space.es.vu")) {
                view.loadUrl(url);
              } else {
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(i);
              }
              return true;
            }
        }

这篇关于在与Android的WebView浏览器中打开外部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆