我想在我的Android应用上打开电子邮件应用程序: 以下代码崩溃 我做错了吗?请提供代码
Intent i = new Intent (Intent.ACTION_SEND,Uri.fromParts("mailto", "testemail@gmail.com", null));
this.startActivity(i);
答案 0 :(得分:93)
/* Create the Intent */
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
/* Fill it with Data */
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"to@email.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Text");
/* Send it off to the Activity-Chooser */
context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
试试这个,它更清楚一点。尽管如此,只有在真实手机中使用该应用程序才能使用电子邮件,因此如果您使用的是模拟器,请在真实手机上试用。
答案 1 :(得分:3)
试试这个:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:"
+ "xyz@abc.com"
+ "?subject=" + "Feedback" + "&body=" + "");
intent.setData(data);
startActivity(intent);
答案 2 :(得分:2)
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,"");
intent.putExtra(android.content.Intent.EXTRA_TEXT, "");
/* Send it off to the Activity-Chooser */
startActivity(Intent.createChooser(intent,"Send"));
答案 3 :(得分:1)
如果可能,例如intent.type ClipDescription.MIMETYPE_TEXT_PLAIN
科特琳:
val intent = Intent(Intent.ACTION_SEND)
intent.type = ClipDescription.MIMETYPE_TEXT_PLAIN
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf("emailId 1", "emailId 2"))
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject for email")
intent.putExtra(android.content.Intent.EXTRA_TEXT, "Description for email")
startActivity(Intent.createChooser(intent,"Send Email"))
Java:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(ClipDescription.MIMETYPE_TEXT_PLAIN);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"emailId 1", "emailId 2"});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject for email");
intent.putExtra(android.content.Intent.EXTRA_TEXT, "Description for email");
startActivity(Intent.createChooser(intent,"Send Email"));