Send Email Intent

Matheus Mello
Matheus Mello
September 2, 2023
Cover Image for Send Email Intent

📧 How to Send Email Intent with Filtered App Options in Android

Are you struggling to filter app options when using the Send Email Intent in your Android app? No worries, we've got you covered! In this guide, we'll show you how to customize the app options to display only email-related apps like Gmail and Yahoo Mail. Let's dive in! 💪

The Issue: Too Many App Options

You might have noticed that when using the Send Email Intent in Android, a dialog opens up displaying a wide range of app options including Bluetooth, Google Docs, Orkut, and many others. This can be overwhelming and confusing for your users, especially if you want to simplify the email sending process.

The Solution: Filtered App Options

To filter the app options and display only email-related apps, you need to modify your code. Here's an example of how to achieve this:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress@emailaddress.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "I'm email body.");
startActivity(Intent.createChooser(intent, "Send Email"));

To filter the app options, you can use the Intent.createChooser() method and pass in a custom Intent object that specifies the desired target apps. Here's an example:

Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"emailaddress@emailaddress.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "I'm email body.");

// Create intent to filter email apps
Intent chooserIntent = Intent.createChooser(emailIntent, "Send Email");

// Add filter for email-related apps
Intent emailAppIntent = new Intent(Intent.ACTION_VIEW);
emailAppIntent.setData(Uri.parse("mailto:"));

// Filter app options based on intent filter
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{emailAppIntent});
startActivity(chooserIntent);

An Example from the Android Market App

If you want to see a practical example of filtered app options in action, try the following steps:

  1. Open the Android Market app.

  2. Open any application where the developer has specified their email address (if you can't find one, you can try my app: Vehicle Diary).

  3. Scroll down to the 'DEVELOPER' section.

  4. Click on 'Send Email'.

In this example, the dialog only displays email apps like Gmail, Yahoo Mail, and others. It excludes non-email-related apps like Bluetooth or Orkut.

Let's Simplify Email Sending

By implementing the filtered app options, you can streamline the email sending experience for your users. No more overwhelming list of app options, just email-related apps for a cleaner interface.

So go ahead and implement this code in your app! Your users will thank you for making it easier to send emails. 🔥

If you have any questions or need further assistance, feel free to leave a comment below. Happy coding! 😄💻

Take Your Tech Career to the Next Level

Our application tracking tool helps you manage your job search effectively. Stay organized, track your progress, and land your dream tech job faster.

Your Product
Product promotion

Share this article

More Articles You Might Like

Latest Articles

Cover Image for How can I echo a newline in a batch file?
batch-filenewlinewindows

How can I echo a newline in a batch file?

Published on March 20, 2060

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Cover Image for How do I run Redis on Windows?
rediswindows

How do I run Redis on Windows?

Published on March 19, 2060

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Cover Image for Best way to strip punctuation from a string
punctuationpythonstring

Best way to strip punctuation from a string

Published on November 1, 2057

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Cover Image for Purge or recreate a Ruby on Rails database
rakeruby-on-railsruby-on-rails-3

Purge or recreate a Ruby on Rails database

Published on November 27, 2032

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my