Reputation: 151
Is it somehow possible to pass a array as a content of a email ?
What I'm trying :
This is all in a onClick
method
Getting the "EditText fields" first
EditText tbLocation = (EditText)findViewById(R.id.tbLocation);
Creating a string out of it
String tbLocationMessage = tbLocation.getText().toString();
And then trying to send a email
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[] {});
email.putExtra(Intent.EXTRA_SUBJECT, "Near Miss Report");
email.putExtra(Intent.EXTRA_TEXT, new String []{tbLocationMessage,tbFuActionMessage,tbImActionMessage,tbIssueToRaiseMessage});
// need this to prompts email client only
email.setType("message/rfc822");
startActivity(Intent.createChooser(email,
"Choose an Email client :"));
}
When I set some breakpoints my arrays are all filled with the text that I entered in the text fields. But then when I choose my email client ("Gmail") Compose text field is empty...
Why is this happening ?
Upvotes: 0
Views: 473
Reputation: 25858
Use the below code snippet to get String object from the array of String and pass it in
private String getMyStringMessage(String[] arr){
StringBuilder builder = new StringBuilder();
for(String s : arr) {
builder.append(s);
}
return builder.toString();
}
email.putExtra(Intent.EXTRA_TEXT, getMyStringMessage(yout_string_array));
Upvotes: 2
Reputation: 15199
Intent.EXTRA_TEXT should be a CharSequence, not an array of strings. Try concatenating them, rather than making an array of them. See: http://developer.android.com/reference/android/content/Intent.html#EXTRA_TEXT
Upvotes: 0