如何从具有单击编号的webviewclient中打开“拨号程序活动"? [英] How to open Dialer Activity from a webviewclient with clicked number?
问题描述
我正在我的应用程序中实现Web视图.现在,当用户单击电话号码时,它会显示 net :: ERR_UNKNOWN_URL_SCHEME .但是,如果我使用铬.它会为拨号器应用程序提供该电话号码.
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.
我的应用程序中需要完全相同的东西.在Web视图中单击电话号码后,需要使用该电话号码打开拨号程序.
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.
这是我用于网络视图的shouldOverrideUrlLoading
方法.我可以看到此处的答案.但我很漂亮android和java的新功能,直到现在我都无法使该功能正常工作.
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;
}
推荐答案
这必须有效.我们需要覆盖webview类的shouldOverrideUrlLoading
方法.并检查url是否包含tel:xxxx
,然后为拨号程序创建一个意图并调用该拨号程序.并且如果它是mailto:
链接
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
这是方法.
@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;
}
}
这篇关于如何从具有单击编号的webviewclient中打开“拨号程序活动"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!