+ startActivity(Intent.createChooser(shareIntent, getString(R.string.share_url)));
+ return true;
+
+ case R.id.open_with:
+ // Convert the URL to an URI.
+ Uri shareUri = Uri.parse(formattedUrlString);
+
+ // Get the host.
+ String shareHost = shareUri.getHost();
+
+ // Create the open with intent with `ACTION_VIEW`.
+ Intent openWithIntent = new Intent(Intent.ACTION_VIEW);
+
+ // Set the data based on the host.
+ if ((shareHost != null) && (shareHost.endsWith("youtube.com") || shareHost.equals("play.google.com") || shareHost.equals("f-droid.org"))) { // Handle App URLs.
+ // Set the URI but not the MIME type. This should open all available apps.
+ openWithIntent.setData(shareUri);
+ } else { // Handle a generic URL.
+ // Set the URI and the MIME type. `"text/html"` should load browser options.
+ openWithIntent.setDataAndType(shareUri, "text/html");
+ }
+
+ // Flag the intent to open in a new task.
+ openWithIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ // Show the chooser.
+ startActivity(Intent.createChooser(openWithIntent, getString(R.string.open_with)));