Reputation: 10392
In my app, i am opening the url using webview. This url opens the some page that contains some phone numbers.Now i want to make a phone call without open the phone dialer if u click on the phone number. is it possible? please can anybody help me.
thanks
Upvotes: 13
Views: 16431
Reputation: 606
shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean
is now depricated.
Use shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean
instead.
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
return if (request?.url?.scheme?.startsWith("tel") == true) {
val intent: Intent = Intent(Intent.ACTION_DIAL, request.url)
view?.context?.startActivity(intent)
true
} else {
super.shouldOverrideUrlLoading(view, request)
}
}
Upvotes: 0
Reputation: 1095
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i("TEST","URL 4: "+url);
if (url.startsWith("http:") || url.startsWith("https:")) {
view.loadUrl(url);
}else if (url.startsWith("tel:")) {
Intent intent = new Intent(Intent.ACTION_DIAL);
// Send phone number to intent as data
intent.setData(Uri.parse(url));
// Start the dialer app activity with number
startActivity(intent);
}
return true;
}
Upvotes: 0
Reputation: 1072
Thanks JackTurky! Here's slightly more, to show how it fits with webView:
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("tel:")) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(intent);
return true;
}
return false;
}
});
Upvotes: 11
Reputation: 13051
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("tel:")) {
Intent intent = new Intent(Intent.ACTION_DIAL,
Uri.parse(url));
startActivity(intent);
}else if(url.startsWith("http:") || url.startsWith("https:")) {
view.loadUrl(url);
}
return true;
}
Upvotes: 22