24

I need to provide feature for users where users can share some data by sending email. I used below code.

    Intent email = new Intent(android.content.Intent.ACTION_SENDTO);
    email.setType("message/rfc822");
    email.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
    email.putExtra(Intent.EXTRA_SUBJECT, subject);
    email.putExtra(Intent.EXTRA_TEXT, message);
    startActivity(Intent.createChooser(email,"Choose an Email client :"));

This shows Email, gmail, Skype and send via bluetooth for user to choose. I dont want user to show Skype,send via bluetooth in this list. What i need to do ? I have WhatsApp in my phone, which does same thing, but doesn't show Email, bluetooth in the list(Settings->help->Contactus->...).only show Email and Gmail in list. I need to do the same.

0

2 Answers 2

46

Try this:

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
            "mailto","[email protected]", null));
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(intent, "Choose an Email client :"));

If you don't have a specific recipient - go like this:

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
            "mailto", "", null));
4
  • i check it. i want only mail client(gmail, yahoo, outlook) in list not Skype,send via bluetooth.what i do..? Feb 12, 2014 at 7:50
  • @Amardeep Edited my answer. However, WhatsApp still uses custom dialog which shows only 2 email client in the list (Gmail and Email) even you have more than 2 email clients.
    – localhost
    Feb 12, 2014 at 7:57
  • its not working in actual device. can i used this email.setType("message/rfc822"); Feb 12, 2014 at 8:16
  • @Amardeep Any error or what? It works for me on Samsung Galaxy Note Android 4.1.2.
    – localhost
    Feb 12, 2014 at 8:31
1

use this method to share via gmail only jus you need to call

startActivity(getSendEmailIntent(context, email,subject, body));





public Intent getSendEmailIntent(Context context, String email,
                    String subject, String body) {
            Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

            try {

                // Explicitly only use Gmail to send
                emailIntent.setClassName("com.google.android.gm",
                        "com.google.android.gm.ComposeActivityGmail");

                emailIntent.setType("text/html");

                // Add the recipients
                if (email != null)
                    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                            new String[] { email });

                if (subject != null)
                    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                            subject);

                if (body != null)
                    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));

                // Add the attachment by specifying a reference to our custom
                // ContentProvider
                // and the specific file of interest
                // emailIntent.putExtra(
                // Intent.EXTRA_STREAM,
                // Uri.parse("content://" + CachedFileProvider.AUTHORITY + "/"
                // + fileName));

                 return emailIntent;
    //          myContext.startActivity(emailIntent);
            } catch (Exception e) {
                emailIntent.setType("text/html");

                // Add the recipients
                if (email != null)
                    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                            new String[] { email });

                if (subject != null)
                    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                            subject);

                if (body != null)
                    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));

    //          myContext.startActivity(Intent.createChooser(emailIntent,
    //                  "Share Via"));
                 return emailIntent;
            }
            }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.