- // Add a Cancel entry, which by default closes the context menu.
- menu.add(R.string.cancel);
- break;
-
- case WebView.HitTestResult.EMAIL_TYPE:
- // Get the target URL.
- linkUrl = hitTestResult.getExtra();
-
- // Set the target URL as the title of the `ContextMenu`.
- menu.setHeaderTitle(linkUrl);
-
- // Add a Write Email entry.
- menu.add(R.string.write_email).setOnMenuItemClickListener(item -> {
- // Use `ACTION_SENDTO` instead of `ACTION_SEND` so that only email programs are launched.
- Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
-
- // Parse the url and set it as the data for the `Intent`.
- emailIntent.setData(Uri.parse("mailto:" + linkUrl));
-
- // `FLAG_ACTIVITY_NEW_TASK` opens the email program in a new task instead as part of Privacy Browser.
- emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
- // Make it so.
- startActivity(emailIntent);
-
- // Consume the event.
- return true;
- });
-
- // Add a Copy Email Address entry.
- menu.add(R.string.copy_email_address).setOnMenuItemClickListener(item -> {
- // Save the email address in a `ClipData`.
- ClipData srcEmailTypeClipData = ClipData.newPlainText(getString(R.string.email_address), linkUrl);
-
- // Set the `ClipData` as the clipboard's primary clip.
- clipboardManager.setPrimaryClip(srcEmailTypeClipData);
-
- // Consume the event.
- return true;
- });
-
- // Add a `Cancel` entry, which by default closes the `ContextMenu`.