user2600853 user2600853 - 2 years ago 112
Android Question

How to send an ArrayList in the body of an e-mail in android?

I want to send in the body of the e-mail an ArrayList with some values.
Like this:

Button bt_send = (Button) findViewById(;
bt_cadastrar_medicos.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, "[email protected]");
intent.putExtra(Intent.EXTRA_SUBJECT, "SUBJECT");
ArrayList<String> array = new ArrayList<String>();
for(int i=0; i<2; i++){
String ii = String.valueOf(i);
intent.putExtra(Intent.EXTRA_TEXT, niveis.get(i));

startActivity(Intent.createChooser(intent, "Choose the app to send:"));

This is just an example, actually I want to add in which array position values that a get from a java class. But in the body just the last value appears, in this case would be the "2".

How do I show all of them in the body? Is that possible?

Thank You.

Answer Source

In your for-loop, this call

intent.putExtra(Intent.EXTRA_TEXT, niveis.get(i));

is replacing the EXTRA_TEXT data on each pass through the loop. You need to build the entire string that you want to send as the EXTRA_TEXT, then add that to the intent via a single call to putExtra(). E.g.

StringBuilder sb = new StringBuilder(); 
for (String s : myArrayList) {
intent.putExtra(Intent.EXTRA_TEXT, sb.toString());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download