A
A
Alexander2019-02-25 20:19:05
Android
Alexander, 2019-02-25 20:19:05

Android. How to open a link like tel:// (telephone) from WebView?

There is a mini-application which consists of WebView. (the site opens in it, and the site, as it were, is an application).
And links like tel:// (phone number) do not open, in the application itself it is written that the document is not available (that is, it tries to open it as a page).
The application has only a couple of functions

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webView = (WebView)findViewById(R.id.webView);
        webView.clearCache(true);
        webView.clearHistory();
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl(url);
        webView.setWebViewClient(new WebViewClient());

    }

    @Override
    public void onBackPressed(){
        if(webView.canGoBack()){
            webView.goBack();
        }else {
            super.onBackPressed();
        }
    }

Here's how to make it so that when you click on a link like tel:// in the application, the body of the link is transferred to the phone application.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2019-02-25
@402d

Slightly sloppy language. Better not google quickly:
www.ohandroid.com/setwebviewclient-setwebchromecli...
WebViewClient is an event interface. By providing your own WebViewClient implementation, you can respond to render events. For example, you can detect when a render starts loading an image from a particular URL, or decides whether to resubmit a POST request to the server.
The WebViewClient has many methods that you can override, most of which you won't be dealing with. However, you need to replace the default implementation of shouldOverrideUrlLoading(WebView, String) for shouldOverrideUrlLoading(WebView, String) . This method determines what happens when a new URL is loaded into the WebView, such as by clicking a link. If you return true, you are saying "Don't process this URL, I process it myself." If you return false, you are saying "Go ahead and load this URL, WebView, I'm not doing anything with it."
url.startsWith("tel")

Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "Your Phone_number"));
startActivity(intent);

"tel:" + "Your Phone_number" already in the right form in the url variable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question