0

I want to send e-mail and when button is clicked I want list of e-mail based applications . When I use below source code it outputs all message based apps as showin in picture

Intent intent2 = new Intent(Intent.ACTION_SEND);
intent2.setData(Uri.parse("mailto:"));
intent2.setType("plain/text");
intent2.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
startActivity(intent2);

When I click on button, such apps are showing

enter image description here

but I want only e-mail based apps, such as. What I should change to get such list of apps?

enter image description here

Just Ahead
  • 2,377
  • 6
  • 16
  • 25

2 Answers2

5

you can use this

 btnReport.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String mailto = "mailto:useremail@gmail.com" +
                    "?cc=" +
                    "&subject=" + Uri.encode("your subject") +
                    "&body=" + Uri.encode("your mail body");
            Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
            emailIntent.setData(Uri.parse(mailto));

            try {
                startActivity(emailIntent);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(context, "Error to open email app", Toast.LENGTH_SHORT).show();
            }
        }
    });
Mehrdad
  • 1,477
  • 15
  • 17
0

Just call an intent for Email in your onClicklistener,

Intent email = new Intent(Intent.ACTION_SEND);  
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});  
email.putExtra(Intent.EXTRA_SUBJECT, subject);  
email.putExtra(Intent.EXTRA_TEXT, message);  

//need this to prompt`enter code here`s email client only  
email.setType("message/rfc822");  

startActivity(Intent.createChooser(email, "Choose an Email client :"));