|
6 | 6 | * Licensed under the MIT License (https://opensource.org/licenses/MIT) |
7 | 7 | */ |
8 | 8 |
|
| 9 | +import android.content.ActivityNotFoundException; |
9 | 10 | import android.view.ViewGroup; |
10 | 11 | import android.app.DownloadManager; |
11 | 12 | import android.app.DownloadManager.Request; |
@@ -522,6 +523,47 @@ public boolean shouldOverrideUrlLoading(final WebView view, final String url) { |
522 | 523 | } |
523 | 524 | } |
524 | 525 |
|
| 526 | + final Uri uri = Uri.parse(url); |
| 527 | + final String scheme = uri.getScheme(); |
| 528 | + |
| 529 | + if (scheme != null) { |
| 530 | + final Intent externalSchemeIntent; |
| 531 | + |
| 532 | + if (scheme.equals("tel")) { |
| 533 | + externalSchemeIntent = new Intent(Intent.ACTION_DIAL, uri); |
| 534 | + } |
| 535 | + else if (scheme.equals("sms")) { |
| 536 | + externalSchemeIntent = new Intent(Intent.ACTION_SENDTO, uri); |
| 537 | + } |
| 538 | + else if (scheme.equals("mailto")) { |
| 539 | + externalSchemeIntent = new Intent(Intent.ACTION_SENDTO, uri); |
| 540 | + } |
| 541 | + else if (scheme.equals("whatsapp")) { |
| 542 | + externalSchemeIntent = new Intent(Intent.ACTION_SENDTO, uri); |
| 543 | + externalSchemeIntent.setPackage("com.whatsapp"); |
| 544 | + } |
| 545 | + else { |
| 546 | + externalSchemeIntent = null; |
| 547 | + } |
| 548 | + |
| 549 | + if (externalSchemeIntent != null) { |
| 550 | + externalSchemeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 551 | + |
| 552 | + try { |
| 553 | + if (mActivity != null && mActivity.get() != null) { |
| 554 | + mActivity.get().startActivity(externalSchemeIntent); |
| 555 | + } |
| 556 | + else { |
| 557 | + getContext().startActivity(externalSchemeIntent); |
| 558 | + } |
| 559 | + } |
| 560 | + catch (ActivityNotFoundException ignored) {} |
| 561 | + |
| 562 | + // cancel the original request |
| 563 | + return true; |
| 564 | + } |
| 565 | + } |
| 566 | + |
525 | 567 | // route the request through the custom URL loading method |
526 | 568 | view.loadUrl(url); |
527 | 569 |
|
|
0 commit comments