Skip to content

Instantly share code, notes, and snippets.

@jtryan
Created July 24, 2016 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtryan/43ce50d0bb64fd57fdb82e4e8e295252 to your computer and use it in GitHub Desktop.
Save jtryan/43ce50d0bb64fd57fdb82e4e8e295252 to your computer and use it in GitHub Desktop.
Android email Intent
// Find the View that shows the ContactUs  category
        TextView contactUs = (TextView) findViewById(R.id.contact);

        // Set a click listener on view
        if (contactUs != null) {
            contactUs.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    String[] emails = {"youremail@gmail.com"};
                    String subject = "This is a way for the user to contact us for support.";
                    String message = "your message";

                    Intent email = new Intent(Intent.ACTION_SENDTO);
                    email.putExtra(Intent.EXTRA_EMAIL, emails);
                    email.putExtra(Intent.EXTRA_SUBJECT, subject);
                    email.putExtra(Intent.EXTRA_TEXT, message);
                    email.setType("*/*");
                    email.setData(Uri.parse("mailto:"));

                    if (email.resolveActivity(getPackageManager()) != null) {
                        startActivity(email);
                    }
                }
            });
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment