4

I'm implementing what would seem to be an extremely simple solution on a stock Nexus 5 with 5.5.1/Lollipop but having difficulty. I wish to store a local HTML page directly on the phone to hold large lists of reference phone numbers:

<a href="tel:123-456-7890">Call Harold's Chicken Shack</a>
<a href="tel:234-567-8901">Call In n' Out Burger</a>

This used to work without any issues, but sometime earlier this year an Android update disabled it. Before, clicking the link would open the dialer on the phone and start a call to the number. Now, another webpage is shown titled "Webpage not available" and containing "The webpage at tel:123-456-7890 could not be loaded because: net::ERR_UNKNOWN_URL_SCHEME" in the body.

I've googled this extensively but remain unclear on the solution.

This problem is discussed here on:
Getting net::ERR_UNKNOWN_URL_SCHEME while calling telephone number from HTML page in Android
but all the responses on that question seem to be either incorrect or describing a solution that isn't referenced.

Some people suggest various formatting changes to the phone number:

<a href="tel:123-456-7890">Call Harold's Chicken Shack</a>
<a href="tel:1234567890">Call Harold's Chicken Shack</a>
<a href="tel:+123-456-7890">Call Harold's Chicken Shack</a>
<a href="tel:+1234567890">Call Harold's Chicken Shack</a>

However, the problem seems unaffected by hyphens or the + symbol.

Next, some people suggested setting a target for the link:

<a href="tel:123-456-7890">Call Harold's Chicken Shack</a>
<a href="tel:123-456-7890" target="_blank">Call Harold's Chicken Shack</a>

This also makes no difference in my testing. It would appear that some people feel this would work if the HTML page being used is in a frame. Just to be clear, the HTML page I am using is a single page, not inside a frame set, and stored locally on the phone.

Some comments seem to discuss different browsers. I am targeting stock Android 5.5.1/Lollipop WebView / HTML Viewer. I can actually confirm that the original code:

<a href="tel:123-456-7890">Call Harold's Chicken Shack</a>

will work correctly if opened in a number of third-party browsers. However, I am seeking a stock solution here.

A number of comments seem to indicate that special permissions need to be set, but there's no indication on where the files even are and I've been unable to find them at all, much less modify them. That makes me wonder if their permissions-related suggestions are even an option on a stock/unrooted Android device.

So, in summary, if you want to have a LOCALLY stored HTML page on your Android phone (not a script, not an app, not even an HTML page that is running JavaScript or something, ONLY a simple local HTML page with an "a href=" link that will put a phone number into the dialer when clicked...) how can this be done?

Thanks for your assistance.

Community
  • 1
  • 1
Paradox
  • 41
  • 1
  • 1
  • 2

4 Answers4

4
import android.content.Intent;
import android.net.Uri;

...

mWebView = (WebView) findViewById(R.id.web_view); 

WebSettings webSettings = mWebView.getSettings(); 
webSettings.setJavaScriptEnabled(true); 

mWebView.setWebViewClient(new WebViewClient(){
    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if( url.startsWith("http:") || url.startsWith("https:") ) {
            return false; 
        } 

        // Otherwise allow the OS to handle things like tel, mailto, etc. 
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity( intent );
        return true; 
    } 
}); 
mWebView.loadUrl(url); 
Black
  • 18,150
  • 39
  • 158
  • 271
tiny sunlight
  • 6,231
  • 3
  • 21
  • 42
  • 1
    Thanks for responding. I'm not really understanding what to do with this code. Where is it supposed to go within the HTML page that I've put my link on? Is it some kind of include for a JavaScript that should be kept as a separate file? How is this called? – Paradox Sep 25 '15 at 05:32
1

Android Webview supports HTML5 very well.

You have to separate the urls from each other. I had the same issue and was wondering, why this kind of link would fire the phone. The Webview.shouldOverrideUrlLoading method does not do the for you, so just write an if-statement to catch the tel:-url.

I easily fixed that with the first answer here: https://stackoverflow.com/a/4339193/4937108

Community
  • 1
  • 1
Chris
  • 11
  • 1
  • 3
0

I made a mistake. i can open dial in browser with android 5.1.1. maybe u can use a other browser!

tiny sunlight
  • 6,231
  • 3
  • 21
  • 42
  • Thanks again for replying. However, I am looking for a method specifically to open an HTML page in Android WebView / HTML Viewer and click a link to open the dialer. I mentioned that my original code has always worked in other browsers however, there are a few ways that WebView relates to the rest of the user experience on an Android phone that are important and have lead me to look for a solution to the WebView problem instead of switching to mobile FireFox or something else. – Paradox Sep 25 '15 at 07:08
  • tel: can be used on html5 webpage.maybe the app disable dial .Or the mobile dont support html5 – tiny sunlight Sep 25 '15 at 09:41
0

Android Webview supports HTML5 very well.

You have to separate the urls from each other. I had the same issue and was wondering, why this kind of link would fire the phone. The Webview.shouldOverrideUrlLoading method does not do the for you, so just write an if-statement to catch the tel:-url.

I easily fixed that with the first answer here: https://stackoverflow.com/a/4339193/4937108

  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes – ThomasVdBerge Apr 30 '18 at 05:29