Tea000
Tea000

Reputation: 101

How to attach 3 fields in email body in an android email application

Normally email apps only have an EditText where the app copies what the user writes and pastes it into the email client's body.
I have 2 more fields, specifically 2 TextViews that contain Longitude and Latitude coordinations and I also want those to appear inside the email body. I'm using this code, but only the latest String appears in the mail (lat)

            Intent emailIntent = new Intent(Intent.ACTION_SEND);
            emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
            emailIntent.putExtra(Intent.EXTRA_TEXT, message);
            emailIntent.putExtra(Intent.EXTRA_TEXT, longi);
            emailIntent.putExtra(Intent.EXTRA_TEXT, lat);
            emailIntent.setType("message/rfc822");
            emailIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
            startActivity(Intent.createChooser(emailIntent, "Choose an Email client"));

Upvotes: 1

Views: 51

Answers (2)

Otra
Otra

Reputation: 8158

Construct a string with all three fields.

String text = "";
text += message + "\n" + longi + "\n" + lat;
emailIntent.putExtra(Intent.EXTRA_TEXT, text);

Of course use text and formatting as you like.

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006869

The second and third times that you call putExtra() for Intent.EXTRA_TEXT, you are replacing the previous value.

Instead, create one string that contains the entire message, including the longi and lat values, and use putExtra() for Intent.EXTRA_TEXT on that one string.

Upvotes: 2

Related Questions