如何通过“菜单”按钮发送电子邮件?我用一个名为“发送”的选项夸大了一个菜单。按下后,它应该打开Intent.ACTION_SEND,然后用户可以选择向我发送电子邮件。
我知道如何通过Button和OnClickListener实现这一目标。但不是通过菜单。下面粘贴的代码不起作用。我做错了什么?
感谢您的时间。
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;
}
答案 0 :(得分:3)
您可以使用以下代码:::
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL, new String[] { "myemail@example.com" });
i.putExtra(Intent.EXTRA_SUBJECT, "Adding new shop to MinuteMap");
i.putExtra(Intent.EXTRA_TEXT, "nll");
startActivity(i);
答案 1 :(得分:2)
试试此代码,
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "abc@xyz.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Subject of the Mail");
emailIntent
.putExtra(
android.content.Intent.EXTRA_TEXT,
"This is my sample Mail");
emailIntent.setType("vnd.android.cursor.dir/email");
startActivity(Intent.createChooser(emailIntent, "Email:"));