Android: Send email with pre-populated fields
Within the AppInfoActivity of my current project, I have a button to send an email to the developer (me!). This button creates an Intent and uses Intent.putExtra to pre-populate the Email, subject and body of the email.
Initially my Email “To” field wasn’t populating – if this is happening to you, it’s probably because it’s expecting a String array (to allow for multiple email addresses) and not a single String object, you’ll notice this is different in the onClick handler below:
public void onEmailButtonClick(View v) {
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { getString(R.string.app_email_address) });
emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_info_email_subject));
emailIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.app_info_email_body));
startActivity(emailIntent);
}
and for completeness, here’s the xml for the string resources referenced:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_info_email_subject">Feedback on someOldApp</string> <string name="app_info_email_body">Hi someOldApp,</string> <string name="app_email_address">someoldapp@samcoles.co.uk</string> </resources>
ANDROID, ANGRY BIRDS SPACE, ANDROID APPS, ANDROID GAMES, ANDROID LIVE WALLPAPERS, ANDROID…
[...]SamColes.co.uk | Android: Send email with pre-populated fields[...]…