在我的应用程序中,我使用Webview打开URL。这个URL打开了一个包含一些电话号码的页面。现在,如果您点击这些电话号码,我想直接进行电话呼叫而不是打开手机拨号器。这是否可能?请问有谁可以帮助我。
感谢。
感谢。
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;
}
谢谢JackTurky!这里稍微多一点内容,以展示它如何适用于webView:
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);
return true;
}
return false;
}
});
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i("TEST","URL 4: "+url);
if (url.startsWith("http:") || url.startsWith("https:")) {
view.loadUrl(url);
}else if (url.startsWith("tel:")) {
Intent intent = new Intent(Intent.ACTION_DIAL);
// Send phone number to intent as data
intent.setData(Uri.parse(url));
// Start the dialer app activity with number
startActivity(intent);
}
return true;
}