[ACCEPTED]-Android - Opening the email application?-android-intent

Accepted answer
Score: 106
/* 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 4 intent for emails only works if you are 3 using the application in a real phone, so 2 if you are using the emulator, try it on 1 a real phone.

Score: 7

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);

0

Score: 3
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"));

0

Score: 3

Prefer to use constants if available like 1 for intent.type ClipDescription.MIMETYPE_TEXT_PLAIN

Kotlin:

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"));

More Related questions