0

我的 webview 应用程序上有一个电话链接:tel:062123658但是当我点击它时,我找不到网页。

这是我的代码:

public class FullscreenActivity extends Activity {

    private WebView webView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullscreen);

        webView = (WebView) findViewById(R.id.webView);
        webView.setWebViewClient(new myWebClient());
        webView.loadUrl("http://www.mywebsite.nl");
        webView.setVerticalScrollBarEnabled(false);
    }

    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.startsWith("tel:")) { 
                Intent intent = new Intent(Intent.ACTION_DIAL,
                        Uri.parse(url)); 
                startActivity(intent); 
        }else if(url.startsWith("http:") || url.startsWith("https:")) {
            view.loadUrl(url);
        }
        return true;
    }

我怎样才能解决这个问题?

4

2 回答 2

1

您应该覆盖 WebViewClient 中的一个函数:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fullscreen);

    webView = (WebView) findViewById(R.id.webView);
    webView.setWebViewClient(new myWebClient());
    webView.loadData("Hello World, <a href=\"tel:3174562564\">317.456.2564</a> ", "text/html","utf-8");
  //webView.loadUrl("http://www.techjini.com/contactus.html");
    webView.setVerticalScrollBarEnabled(false);
}

class myWebClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
           if (url.startsWith("tel:")) { 
               Intent intent = new Intent(Intent.ACTION_DIAL,
                       Uri.parse(url)); 
               startActivity(intent); 
       }else if(url.startsWith("http:") || url.startsWith("https:")) {
           view.loadUrl(url);
       }
       return true;
    }
}
于 2013-12-02T11:35:26.227 回答
0

试试这个方法:

webView.setWebViewClient(new WebViewClient() {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        if (url.startsWith("tel:")) { 
            Intent intent = new Intent(Intent.ACTION_DIAL,
                    Uri.parse(url)); 
            startActivity(intent); 
        }else if(url.startsWith("http:") || url.startsWith("https:")) {
            view.loadUrl(url);
        }
        return true;
    }
});
于 2013-12-02T12:08:56.697 回答