Java 如何从菜单发送电子邮件?
如何通过“菜单”按钮发送电子邮件?我用一个名为“发送”的选项来扩展菜单。一旦按下,它将打开Intent.ACTION\u SEND,然后用户可以选择向我发送电子邮件 我知道如何通过按钮和OnClickListener实现这一点。但不是通过菜单。下面粘贴的代码不起作用。我做错了什么 谢谢你抽出时间 CustomStore活动:Java 如何从菜单发送电子邮件?,java,android,email,Java,Android,Email,如何通过“菜单”按钮发送电子邮件?我用一个名为“发送”的选项来扩展菜单。一旦按下,它将打开Intent.ACTION\u SEND,然后用户可以选择向我发送电子邮件 我知道如何通过按钮和OnClickListener实现这一点。但不是通过菜单。下面粘贴的代码不起作用。我做错了什么 谢谢你抽出时间 CustomStore活动: public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMen
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;
}
您可以使用以下代码:::
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);
您可以使用以下代码:::
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);
试试这个代码
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:"));
试试这个代码
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:"));
找到答案:星触觉(i);我是故意的,没有让它开始。谢谢你#android开发者-用户:“自述”指出了这一点。我还添加了答案。如果得到解决方案,请粘贴你的答案。因此,它可以帮助其他人找到答案:星触觉(i);我是故意的,没有让它开始。谢谢你#android开发者-用户:“自述”指出了这一点。我还添加了答案。如果得到解决方案,请粘贴你的答案。这样才能对其他人有所帮助谢谢你,阿加瓦尔,这正是我所做的。我刚刚添加了“startActivity(I)”。愚蠢的错误,干杯。谢谢你,阿加瓦尔,这正是我所做的。我刚刚添加了“startActivity(I)”。愚蠢的错误,干杯。