Android - Opening the email application?

2019-03-09 15:54发布

I want to open the email application on my android app: The following code crashes Am I doing anything wrong? please provide code

Intent i = new Intent (Intent.ACTION_SEND,Uri.fromParts("mailto", "testemail@gmail.com", null));
this.startActivity(i);

3条回答
劳资没心,怎么记你
2楼-- · 2019-03-09 16:39
/* 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..."));

Try this, it is a bit more clear. Nonetheless intent for emails only works if you are using the application in a real phone, so if you are using the emulator, try it on a real phone.

查看更多
来,给爷笑一个
3楼-- · 2019-03-09 16:50

Try This :

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri data = Uri.parse("mailto:"
            + "xyz@abc.com"
            + "?subject=" + "Feedback" + "&body=" + "");
    intent.setData(data);
    startActivity(intent);
查看更多
神经病院院长
4楼-- · 2019-03-09 16:51
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"));
查看更多
登录 后发表回答