Getting net::ERR_UNKNOWN_URL_SCHEME while calling telephone number from HTML page in Android
Asked Answered
M

3

17

I am getting "net::ERR_UNKNOWN_URL_SCHEME" while calling a telephone number option from an HTML page in Android. Do I need to add any permission(s) in the manifest to get this working? I haven't added anything in the manifest so far. Here's the HTML Code:

<a href="tel:+1800229933">Call us free!</a>

Mudfish answered 11/7, 2014 at 12:11 Comment(5)
can you please post html code ?Looseleaf
<a href="tel:+1800229933">Call us free!</a>Mudfish
try by removing '+' from your telephone number.Nealson
@Parvaz Bhaskar I tried it but it didnt work out.Mudfish
@Karthik, your this problem is resolved or not?Authors
C
38

The following should work and not require any permissions in the manifest (basically override shouldOverrideUrlLoading and handle links separately from tel, mailto, etc.):

    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);

Also, note that in the above snippet I am enabling JavaScript, which you will also most likely want, but if for some reason you don't, just remove those 2 lines.

Contrariety answered 28/8, 2014 at 19:6 Comment(2)
Works like a charm for me. Someone select it as best answerRuisdael
How can I donate?Working
K
2

I had this issue occurring with mailto: and tel: links inside an iframe (in Chrome, not a webview). Clicking the links would show the grey "page not found" page and inspecting the page showed it had a ERR_UNKNOWN_URL_SCHEME error.

Adding target="_blank", as suggested by this discussion of the issue fixed the problem for me.

Knighterrant answered 19/5, 2015 at 5:32 Comment(2)
Add the target attribute to the anchor tag: <a href="mailto:[email protected]" target="_blank">link text</a>Knighterrant
strAbout = strAbout + "<br /> Email: " + jsonObj.getString("email"); strAbout = strAbout + "<br /> Phone Number: " + jsonObj.getString("contact_no"); I am loading this string on web view after this Spannable sp = new SpannableString(Html.fromHtml(strAbout)); Linkify.addLinks(sp, Linkify.ALL); final String html = "<body>" + Html.toHtml(sp) + "</body>"; webViewAbout.getSettings().setJavaScriptEnabled(true); webViewAbout.loadData(html, "text/html", "utf-8"); I am not able to add target="_blank"Sciomancy
L
0

Try this way,hope this will help you to solve your problem.

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center">

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

MyActivity.java

public class MyActivity extends Activity {

    private WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        webView = (WebView) findViewById(R.id.webView);
        webView.loadData("<a href=\"tel:+1800229933\">Call us free!</a>", "text/html", "utf-8");
    }

}

Please add this permission in AndroidManifest.xml

<uses-permission android:name="android.permission.CALL_PHONE"/>
Looseleaf answered 11/7, 2014 at 12:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.