簡體   English   中英

為什么我無法點擊Android WebView中的電話號碼?

[英]Why am I unable to click on a phone number in Android WebView?

我正在學習本教程。 我正在為我的一個域制作一個Android應用程序,它是一個非常基本的查看器,顯示主頁,用戶可以導航到應用程序內的其他頁面(而不是彈出窗口,要求他們使用巫婆瀏覽器)但是,我也有網站上的電話號碼作為鏈接,例如在這個.tel頁面中,你可以將鼠標懸停在上面,看到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上運行它,但結果是一樣的

任何幫助表示感謝

我用這個解決了它

 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; } 

這是第一個解決方案的一個編輯的版本在這里 (我打開這個問題之前,曾經嘗試),並通知我如何注釋掉的部分地方將排除我的主頁,這樣它會打開在WebView中的所有頁面

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM