How do you send email through a “menu” button? I have inflated a menu with an option called “send”. Once pressed it should open the Intent.ACTION_SEND and then the user can choose to send me an email.
I know how to achieve this via a Button and OnClickListener. But not through a menu. The code pasted below does not work. What am I doing wrong?
Thank you for your time.
CustomStoreActivity:
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.customstore_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.send:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL,
new String[] { "myemail@myemail.com" });
i.putExtra(Intent.EXTRA_SUBJECT, "Adding new shop to MinuteMap");
i.putExtra(Intent.EXTRA_TEXT, "nll");
// shopName + shopTimeM1);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
you can use below code :::