Reputation: 475
I am making an email sending application on Android. Only To field is visible when I launch my application through a button click.
Why doesn’t it show Cc, Bcc and Subject fields? How to add these fields to my app? And how to show a default email address in the To field? (Now nothing is written in the To field by default.)
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
clickBtn = (Button) findViewById(R.id.sendemail);
clickBtn.setText("Send email");
clickBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { "[email protected]","[email protected]" };
String aEmailCCList[] = { "[email protected]","[email protected]"};
String aEmailBCCList[] = { "[email protected]" };
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
emailIntent.putExtra(android.content.Intent.EXTRA_CC, aEmailCCList);
emailIntent.putExtra(android.content.Intent.EXTRA_BCC, aEmailBCCList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My subject");
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "My message body.");
startActivity(emailIntent);
//startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
}
});
Upvotes: 16
Views: 11076
Reputation: 73
Best solution of this problem is
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:[email protected][email protected]&subject=subject text ...&body= extra text ")
startActivity(intent)
Upvotes: 0
Reputation: 11
EXTRA_CC is deprecated but is this way maybe resolve:
...
intent.setData(Uri.parse("mailto:[email protected][email protected]"));
...
Upvotes: 1
Reputation: 221
intent.putExtra(Intent.EXTRA_CC, new String[] { "[email protected]" });
You just had to make the second parameter a string array
Upvotes: 22