Reputation: 481
I want to send email to three email id's at once if the button is clicked, via the email clients installed in the user's phone.
I am using the code below, as it is a onClickListener and Switch case:
public class ContactInfo extends Activity implements OnClickListener {
Button bcall,bmail;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.contactinfo);
bcall=(Button)findViewById(R.id.bcall);
bmail=(Button)findViewById(R.id.bmail);
bcall.setOnClickListener(this);
bmail.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent launch;
switch(v.getId()){
case R.id.bcall:
launch = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:+10000000"));
startActivity(launch);
break;
case R.id.bmail:
launch = new Intent(android.content.Intent.ACTION_SEND);
launch.setType("text/plain");
launch.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]", "[email protected]", "[email protected]"});
launch.putExtra(Intent.EXTRA_SUBJECT, "restaurant");
launch.putExtra(Intent.EXTRA_TEXT, "Sent via - Android Application");
try{
startActivity(launch);
}catch(android.content.ActivityNotFoundException ex){
Toast.makeText(ContactInfo.this, "There are no Email Clients", Toast.LENGTH_LONG).show();
}
break;
}
}
It is working but it is not taking any given email addresses in the email id column.
Upvotes: 0
Views: 104
Reputation: 5234
Use it like below.
launch = new Intent(Intent.ACTION_SEND);
launch.setType("text/plain");
launch .putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {
"[email protected]", "[email protected]" });
launch .putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
You have to use new String[]
array to send email to multiple people. Also change ACTION_SENDTO
to ACTION_SEND
...
Hope this will help you.
Upvotes: 1
Reputation: 5068
change
launch.putExtra(Intent.EXTRA_EMAIL, "[email protected], [email protected], [email protected]");
to this :
launch.putExtra(Intent.EXTRA_EMAIL,new String[]{
"[email protected], [email protected], [email protected]"});
Upvotes: 0