【问题标题】:Why am I unable to click on a phone number in Android WebView?为什么我无法在 Android WebView 中点击电话号码?
【发布时间】:2015-02-27 00:39:25
【问题描述】:

我关注this tutorial. 我正在为我的一个域制作一个 android 应用程序,它是一个非常基本的查看器,显示主页,用户可以导航到应用程序内的其他页面(而不是弹出窗口要求他们使用女巫浏览器)但是,我也有站点中的电话号码作为链接,例如在this .tel page 中,您可以将鼠标悬停在我在浏览器中单击电话时看到 calto:xxxxx,它会给我带来我希望的拨号。当我在我的 webview 应用程序上单击它时,它也可以通过调出拨号应用程序来工作。

但是在执行以下代码以打开应用程序内的所有页面和链接后,它不起作用。它在应用程序内给我一条消息,因为我无法打开它

// Force links and redirects to open in the WebView instead of in a browser
mWebView.setWebViewClient(new WebViewClient());

所以我用它来使其他请求的域(我也希望电话号码)在另一个应用程序、浏览器(也希望拨号应用程序)中打开,并且它适用于其他网站,但是当我点击电话时编号它只会给我这个错误并强制关闭应用程序

public class MyAppWebViewClient extends WebViewClient {
        
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if(Uri.parse(url).getHost().endsWith("html5rocks.com")) {
                return false;
            }
             
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            view.getContext().startActivity(intent);
            return true;
        }
    }

错误

02-24 18:56:20.065  15423-15423/com.clicnet.bandeirantestel A/chromium﹕ [FATAL:jni_android.cc(271)] Check failed: false.
02-24 18:56:20.075  15423-15423/com.clicnet.bandeirantestel A/libc﹕ Fatal signal 6 (SIGABRT), code -6 in tid 15423 (bandeirantestel)
我试图在棒棒糖和 ics 上运行它,但结果是一样的

任何帮助表示赞赏 谢谢

【问题讨论】:

    标签: javascript android webview


    【解决方案1】:

    我用这个解决了它

    public boolean shouldOverrideUrlLoading(WebView view, String url)
           {Uri query_string=Uri.parse(url);
            String query_scheme=query_string.getScheme();
            String query_host=query_string.getHost();
            if ((query_scheme.equalsIgnoreCase("https") || query_scheme.equalsIgnoreCase("http"))
                && query_host!=null // && query_host.equalsIgnoreCase(Uri.parse(URL_SERVER).getHost())
                && query_string.getQueryParameter("new_window")==null
               )
               {return false;//handle the load by webview
               }
            try
               {Intent intent=new Intent(Intent.ACTION_VIEW, query_string);
                String[] body=url.split("\\?body=");
                if (query_scheme.equalsIgnoreCase("sms") && body.length>1)
                   {intent=new Intent(Intent.ACTION_VIEW, Uri.parse(body[0]));
                    intent.putExtra("sms_body", URLDecoder.decode(body[1]));
                   }
                view.getContext().startActivity(intent);//handle the load by os
               }
            catch (Exception e) {}
            return true;
           }

    这是第一个解决方案 here 的编辑版本(我在打开这个问题之前已经尝试过)并注意我是如何注释掉它会排除我的主页的部分,这样它将打开 WebView 中的所有页面

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-01
      • 1970-01-01
      相关资源
      最近更新 更多