Problem with Intent.EXTRA_EMAIL to send an email

0

I have this code:

 button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent Mail = new Intent(Intent.ACTION_SEND);
            Mail.setData(Uri.parse("mailto:"));

            Mail.putExtra(Intent.EXTRA_EMAIL,"[email protected]");
            Mail.putExtra(Intent.EXTRA_CC,"[email protected]");
            Mail.putExtra(Intent.EXTRA_SUBJECT,"tema");
            Mail.putExtra(Intent.EXTRA_TEXT,"cuerpo correo");

            Mail.setType("message/rfc822");
            startActivity(Intent.createChooser(Mail,"send Email"));

        }
    });

what happens is that when it is executed in the gmail application it shows the subject and the body, but it does not show for whom it is addressed or the copy

Could it be a version problem or something like that?

    
asked by Sergio 24.12.2018 в 05:36
source

1 answer

1

In case it helps you, what I do is that I send the sender an array, in case I want to send it to several at the same time. For example, this code works perfectly for me:

                String[] TO = {"[email protected]"};
                String[] CC = {""};
                Intent emailIntent = new Intent(Intent.ACTION_SEND);
                emailIntent.setData(Uri.parse("mailto:"));
                emailIntent.setType("text/plain");
                emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
                emailIntent.putExtra(Intent.EXTRA_CC, CC);
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Aquí tu asunto");

                try {
                    startActivity(emailIntent);
                    finish();
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(AjustesActivity.this, "No tienes ningún gestor de correo instalado", Toast.LENGTH_SHORT).show();
                }

And I verify if you have any mail manager installed or not before taking any action.

Eye, to verify it, you have to do it on a real device, since on an emulator it does not usually work well. I imagine that by configuration theme.

Good luck!

    
answered by 24.12.2018 / 09:21
source