Android: Sending Email using Intents

Source :

Thanks to

Many things on Android are as easy as starting an Activity using the right Intent. Sending an email to a specific recipient is one of those things.
Sadly, there is much bad advice out there on how to send emails using Intents. Because I write an open source email app I have a pretty good understanding of what goes on behind the scenes. That’s why I believe I know better than all those other people :)

Creating such an Intent might look like this:

Generating such a mailto URI is a bit tedious because you have to percent-encode certain characters as you can see in the example above.
Android’s Uri.Builder class would be the perfect fit since it makes it easy to add query parameters while taking care of the encoding. Unfortunately, building Uri instances doesn’t work very well for non-hierarchical URIs like mailto URIs. One way to work around that is to manually construct the URI and dealing with the encoding.

Comments (0)

Leave a comment

Your email address will not be published. Required fields are marked *