String value = text.getText().toString();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"test#test.test"});
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, value);
startActivity(Intent.createChooser(intent, "Send Email"));
this code runs, but it show a list of applications like notepad (and other notepad app), whatsapp (and several chat app).
I need a list of only email clients. I done a long search but the code is always same.
try the following code with content type:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some#email.address" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));
Edit1: Check out this post for sending email directly without opening the email client.
Related
I have multiple posts about sending an email and even in the Android documentations. IT does not seem to work. I want to basically to allow the user to choose their email programs to send an email. Here is the code
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("*/*");
emailIntent.putExtra(Intent.EXTRA_EMAIL , new String[]{"xyz#gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT , "msg");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
However it does nothing (ie no activity)
What is it that I am doing wrong? If I use Action.Send then it display all social medial platforms including facebook and whatsapp ..etc
Thank you
This is taken from Adroid developers site and combining with this question:
public void composeEmail(String[] addresses, String subject, String msessage) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("application/octet-stream");
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
Note I made a few changes to match the case of the question.
How can I open a device email to send an email on the new update of android? it's showing a list of applications with support text/message/html/plain with the following code?
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{context.getString("email_to")});
intent.putExtra(Intent.EXTRA_SUBJECT, context.getString("email_subject"));
context.startActivity(Intent.createChooser(intent, context.getString("email_body")));
This Intent will work For Email client with mailto Uri:
try {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"example.yahoo.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "App feedback");
startActivity(intent);
} catch (android.content.ActivityNotFoundException ex) {
ToastUtil.showShortToast(getActivity(), "There are no email client installed on your device.");
}
I have found the following code to open the email app programmatically use the following code. I hope this may solve your problem.
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("mailto:"+"email_to"));
intent.putExtra(Intent.EXTRA_SUBJECT, "email_subject");
intent.putExtra(Intent.EXTRA_TEXT, "email_body");
startActivity(intent);
In Android Studio I wish to send an email on a button click. I am using the following code till I work out what is going on before I start changing thing.
String[] TO = {"ABC#yahoo.com.au"};
String[] CC = {"xyz#gmail.com"};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Email subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Some message added in here");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this,
"There is no email client installed.", Toast.LENGTH_SHORT).show();
}
This works fine and well and shows up on my phone with the email content being as expected, however the email content, "Some message added in here" line is clearly hardcoded. I obviously wish to add in my own content by doing the following
String content = "Information I want to send";
emailIntent.putExtra(Intent.EXTRA_TEXT, content);
But for some reason the email content is blank. Why does is a string "content" recognised but a String variable x is not?
Check This Examples
By Looking at your code i only found problem in setting
emailIntent.setType(text/plain).
May Be you are using Gmail for sending mails(So you have to check second example).
Send Email (to Phone Email Client)
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some#email.address" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));
Send Email (to Gmail)
Gmail does not examine the extra Intent fields, so in order to use this intent, you need to use the Intent.ACTION_SENDTO and pass a mailto: URI with the subject and body URL encoded.
String uriText =
"mailto:youremail#gmail.com" +
"?subject=" + Uri.encode("some subject text here") +
"&body=" + Uri.encode("some text here");
Uri uri = Uri.parse(uriText);
Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
sendIntent.setData(uri);
startActivity(Intent.createChooser(sendIntent, "Send email"));
I've integrated code to send an email from my app.i have search on that and found the solution which i have already integrated but it didn't work for me.
Basically, The code include the text and the subject but does not add the email address (on which we have to send email) in gmail.
Can any one help me?
protected void sendEmail (String strtwi){
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, "projectmyangel#hotmail.com");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Spread More Cheer!");
emailIntent.putExtra(Intent.EXTRA_TEXT, strtwi);
emailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(emailIntent, "Email"));
}
change this line
emailIntent.putExtra(Intent.EXTRA_EMAIL, "projectmyangel#hotmail.com");
with
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"myEmail#gmail.com"});
if above didn't solve your issue try below:
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"myEmail#gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(Intent.createChooser(intent, "Contact Me..."));
}
Android API does not supply the assignment of the email address (on which to send mail).
The intent is just a message that sent to the application you select in Intent.createChooser(emailIntent, "Email") and fill in the necessary columns refer to the information you have given.
Since the email address that the mail sent from differs from one user to another, it is better to choose them in the email application the user select rather than in your application.
I'm trying to have the user e-mail me when they click a button, and use this code to do so. While it works, it brings up a lot of other applications that cant handle e-mail, like Twitter and Facebook. What's missing?
String[] email = {"evan#example.com"};
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_EMAIL,email);
context.startActivity(sendIntent);
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent .setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"evan#example.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg);
startActivity(Intent.createChooser(emailIntent, "Send mail"));
// start the activity
context.startActivity(sendIntent);
// start the activity asking the user how to send the email
context.startActivity(Intent.createChooser(sendIntent, "Email:"));
So you need to remove the last line.
see http://developer.android.com/reference/android/content/Intent.html