Pol Hallen
Pol Hallen

Reputation: 1872

intent to share text to email clients (only email clients)

String value = text.getText().toString();

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
        intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
        intent.putExtra(Intent.EXTRA_TEXT, value);

        startActivity(Intent.createChooser(intent, "Send Email"));

this code runs, but it show a list of applications like notepad (and other notepad app), whatsapp (and several chat app).

I need a list of only email clients. I done a long search but the code is always same.

Upvotes: 1

Views: 905

Answers (1)

Praful Bhatnagar
Praful Bhatnagar

Reputation: 7435

try the following code with content type:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));

Edit1: Check out this post for sending email directly without opening the email client.

Upvotes: 2

Related Questions