我可以在 Android 上通过 HTML 拨打电话吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2774243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I make a phone call from HTML on Android?
提问by Kevin
To make a phone call via HTML on an iPhone I create an <A/>
tag with an href formatted as: <a href='tel:123-555-1212'>Dial Me</a>
.
为了使通过HTML电话在iPhone上创建一个<A/>
具有格式化为href标记:<a href='tel:123-555-1212'>Dial Me</a>
。
Is there an equivelant for HTML on Android?
Android 上是否有 HTML 的等效项?
CLARIFICATION - using the format href='tele:123-555-1212' does indeed work on on android. I was testing the app within a native Java wrapper on the device. It does not appear as if we can make a call from a web application hosted in a Native Wrapper.
澄清 - 使用格式 href='tele:123-555-1212' 确实适用于 android。我正在设备上的本机 Java 包装器中测试该应用程序。我们似乎无法从原生包装器中托管的 Web 应用程序进行调用。
回答by systempuntoout
Yes you can; it works on Androidtoo:
是的你可以; 它也适用于Android:
tel: phone_number
Calls the entered phone number. Valid telephone numbers as defined in the IETF RFC 3966 are accepted. Valid examples include the following:* tel:2125551212 * tel: (212) 555 1212
tel: phone_number
拨打输入的电话号码。接受 IETF RFC 3966 中定义的有效电话号码。有效示例包括:* tel:2125551212 * tel: (212) 555 1212
The Android browser uses the Phone app to handle the “tel” scheme, as defined by RFC 3966.
Clicking a link like:
Android 浏览器使用电话应用程序来处理 RFC 3966 定义的“电话”方案。
单击如下链接:
<a href="tel:2125551212">2125551212</a>
on Android will bring up the Phone app and pre-enter the digits for 2125551212 without autodialing.
在 Android 上将调出电话应用程序并预先输入 2125551212 的数字,而无需自动拨号。
Have a look to RFC3966
看看RFC3966
回答by Martyn
I have just written an app which can make a call from a web page - I don't know if this is any use to you, but I include anyway:
我刚刚编写了一个可以从网页上拨打电话的应用程序-我不知道这对您是否有用,但无论如何我都包括:
in your onCreate you'll need to use a webview and assign a WebViewClient, as below:
在您的 onCreate 中,您需要使用 webview 并分配一个 WebViewClient,如下所示:
browser = (WebView) findViewById(R.id.webkit);
browser.setWebViewClient(new InternalWebViewClient());
then handle the click on a phone number like this:
然后像这样处理电话号码的点击:
private class InternalWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.indexOf("tel:") > -1) {
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url)));
return true;
} else {
return false;
}
}
}
Let me know if you need more pointers.
如果您需要更多指示,请告诉我。
回答by Tarka
Generally on Android, if you simply display the phone number, and the user taps on it, it will pull it up in the dialer. So, you could simply do
一般在Android上,如果你只是简单地显示电话号码,用户点击它,它就会在拨号器中拉出来。所以,你可以简单地做
For more information, call us at <b>416-555-1234</b>
When the user taps on the bold part, since it's formatted like a phone number, the dialer will pop up, and show 4165551234
in the phone number field. The user then just has to hit the call button.
当用户点击粗体部分时,由于它的格式类似于电话号码,拨号器将弹出,并显示4165551234
在电话号码字段中。然后用户只需点击呼叫按钮。
You might be able to do
你也许可以做到
For more information, call us at <a href='tel:416-555-1234'>416-555-1234</a>
to cover both devices, but I'm not sure how well this would work. I'll give it a try shortly and let you know.
覆盖这两种设备,但我不确定这会如何工作。我很快就会试一试,然后告诉你。
EDIT: I just gave this a try on my HTC Magic running a rooted Rogers 1.5 with SenseUI:
编辑:我刚刚在我的 HTC Magic 上尝试了这个,它运行了带有 SenseUI 的 Rogers 1.5:
For more information, call us at <a href='tel:416-555-1234'>416-555-1234</a><br />
<br />
Call at <a href='tel:416-555-1234'>our number</a>
<br />
<br />
<a href='416-555-1234'>Blah</a>
<br />
<br />
For more info, call <b>416-555-1234</b>
The first one, surrounding with the link and printing the phone number, worked perfectly. Pulled up the dialer with the hyphens and all. The second, saying our number
with the link, worked exactly the same. This means that using <a href='tel:xxx-xxx-xxxx'>
should work across the board, but I wouldn't suggest taking my one test as conclusive.
第一个,周围有链接并打印电话号码,效果很好。拉起带有连字符和所有内容的拨号器。第二个,our number
用链接说,工作完全一样。这意味着使用<a href='tel:xxx-xxx-xxxx'>
应该全面工作,但我不建议将我的一项测试视为结论性的。
Linking straight to the number did the expected: Tried to pull up the nonexistent file from the server.
直接链接到数字达到预期:试图从服务器中提取不存在的文件。
The last one did as I mentioned above, and pulled up the dialer, but without the nice formatting hyphens.
最后一个像我上面提到的那样,拉起拨号器,但没有漂亮的格式连字符。