Can I make a phone call from HTML on Android?

后端 未结 3 1775
感动是毒
感动是毒 2020-11-27 12:30

To make a phone call via HTML on an iPhone I create an tag with an href formatted as: Dial Me

相关标签:
3条回答
  • 2020-11-27 13:17

    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:

    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.

    0 讨论(0)
  • 2020-11-27 13:21

    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

    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.

    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:

    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.

    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.

    0 讨论(0)
  • 2020-11-27 13:22

    Yes you can; it works on Android too:

    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
    

    The Android browser uses the Phone app to handle the “tel” scheme, as defined by RFC 3966.
    Clicking a link like:

    <a href="tel:2125551212">2125551212</a>
    

    on Android will bring up the Phone app and pre-enter the digits for 2125551212 without autodialing.

    Have a look to RFC3966

    0 讨论(0)
提交回复
热议问题