Skip to content

Commit 419baa8

Browse files
committed
fix: tel and mailto links
1 parent b6030eb commit 419baa8

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

app/src/main/java/com/webview/myapplication/MainActivity.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,26 @@ private class HelloWebViewClient extends WebViewClient {
276276
public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
277277
String host = Uri.parse(url).getHost();
278278
boolean isAllowed = false;
279+
280+
if (url.startsWith("tel:")) {
281+
Intent tel = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
282+
startActivity(tel);
283+
return true;
284+
}
285+
286+
if (url.contains("mailto:")){
287+
view.getContext().startActivity(
288+
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
289+
}
290+
291+
if (host == null) {
292+
isAllowed = true; // mailto: links
293+
}
279294
if (!STARTUP_URL.isEmpty() && url.equals(STARTUP_URL)) {
280295
isAllowed = true;
281296
}
282297
for (String domain : ALLOWED_DOMAINS) {
283-
if (host.equals(domain) || host.equals("www." + domain) || host.equals("m." + domain)) {
298+
if (host == null || host.equals(domain) || host.equals("www." + domain) || host.equals("m." + domain)) {
284299
isAllowed = true;
285300
break;
286301
}

0 commit comments

Comments
 (0)