How to open Dialer Activity from a webviewclient with clicked number?

浪子不回头ぞ 提交于 2019-12-08 03:29:56

问题


I am implementing a web view in my application. now when a user clicks on a phone number it shows net::ERR_UNKNOWN_URL_SCHEME. But if i use chrome. it brings the dialer application with that phonenumber.

I need the exact same thing in my application. When a phone number is clicked within webview then the dialer needs to be opened with that phone number.

Here is my shouldOverrideUrlLoading Method for the webview. I can see there is answer here. But i am pretty new to android and java and i couldn't make this thing work till now.

 public boolean shouldOverrideUrlLoading(WebView view, String url){
        progressBar.setVisibility(view.VISIBLE);
        view.loadUrl(url);
        return true;
   }

回答1:


This must be working. we need to override the shouldOverrideUrlLoading method of the webview class. and check if the url contains the tel:xxxx Then create an intent for the dialer and invoke the dialer. and we can call any application we want like gmail app if its a mailto: link

here is the methode.

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
   if(url.contains("tel:")) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse(url));
        startActivity(intent);
        return true;
   } else {
        progressBar.setVisibility(view.VISIBLE);
        view.loadUrl(url);
        return true;
   }
}


来源:https://stackoverflow.com/questions/38933852/how-to-open-dialer-activity-from-a-webviewclient-with-clicked-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!