0

I try to send email and take text for it from several EditTexts. But when I click the button, I see only the last one EditText in a body of email.

Whats' wrong with it?

private View.OnClickListener myListener = new View.OnClickListener() {
    public void onClick(View v) {
        Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        emailIntent.setType("message/rfc822"); //specifies message for email app.
        emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"my_email@gmail.com"} );
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Заявка на замер");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Имя клиента: " + getOrderName());
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Номер телефона : " + getOrderPhone());
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Адрес : " + getOrderAdress());
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Дата : " + getOrderDate() );
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Удобное время : " + getOrderTime() );
        startActivity(Intent.createChooser(emailIntent, "Выберите почтовый сервис"));
    }
};

As result in email body i see only last one:

Удобное время 
Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98

4 Answers4

1

Try like below, it will work for you

by merging strings in one you can achieve what you exactly want

    private View.OnClickListener myListener = new View.OnClickListener() {
            public void onClick(View v) {
                Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
                emailIntent.setType("message/rfc822"); //specifies message for email app.
                emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"my_email@gmail.com"} );
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Заявка на замер");


                String body ="Имя клиента: " + getOrderName()+"\n"+
                             "Номер телефона : " + getOrderPhone()+"\n"+
                             "Адрес : " + getOrderAdress()+"\n"+
                             "Дата : " + getOrderDate()+"\n"+
                             "Удобное время : " + getOrderTime();
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
                startActivity(Intent.createChooser(emailIntent, "Выберите почтовый сервис"));


            }
    };

Happy Coding!

Shrenik Shah
  • 1,900
  • 1
  • 11
  • 19
1

You need to use StringBuilder in your case as each time the EXTRA_TEXT is replaced when you set a new value to it.

You might do something like this.

StringBuilder sb;

sb.append("Имя клиента: " + getOrderName());
sb.append('\n');
sb.append("Номер телефона : " + getOrderPhone());
sb.append('\n');
sb.append("Адрес : " + getOrderAdress());
sb.append('\n');
// ... Others 

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,sb);
Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
1

Extra Text which you are trying to send is a one key identifier. So, it will get replaced everytime when you putExtra. This is the reason why only your last putExtra is getting added.

Try to concatenate your message string and then add it to putExtra.

Jaydroid
  • 334
  • 3
  • 13
0

May be this will help. Create a string "email_body" and put whole body part of email in it and then pass it in Intent.

String email_body="Имя клиента: "+getOrderName()+"\nНомер телефона : "+getOrderPhone()+.......+ getOrderTime();

And then in your click listener do this.

    Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType("message/rfc822"); //specifies message for email app.
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"my_email@gmail.com"} );
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Заявка на замер");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,email_body);
    startActivity(Intent.createChooser(emailIntent, "Выберите почтовый сервис"));
Danish Ansari
  • 451
  • 1
  • 6
  • 22