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
Related
when using ACTION_SEND to send emails, is there a way to check if result was successful?
here is my code sample:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
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");
startActivity(Intent.createChooser(emailIntent, "Email:"));
Based on this posting: Get Mail Sent Notification in onActivityResult "Android" it sounds like the problem is that there is no guarantee that the client responsible for handling the intent is going to setActiviyResult, so there's no one way to get it. You'll have to check to see if the client that is handling the intent will send back a status.
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.
I had developed the email sending functionality in my Application where I need to send the email with the specified subject. I have done that but I need that as soon as I click the Email Icon It sets some particular piece of Information in the Body part of the email format. It could be any information that I have with me.
Is it possible to set the data in the Email Body in android, I don't want to write anything in the Body of the mail.
Thanks,
DavidBrown
final Intent emailIntent = new Intent( android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "abc#gmail.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Email Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"Email Body");
startActivity(Intent.createChooser(
emailIntent, "Send mail..."));
Intent.EXTRA_TEXT is what you are looking for.
Try this
intent.putExtra(Intent.EXTRA_TEXT ,
"body of email -- add text what you want ");
This can be useful for you..
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"support#arboristapp.com"});
emailIntent.putExtra(Intent.EXTRA_CC, new String[]{""});
emailIntent.putExtra(Intent.EXTRA_BCC, new String[]{""});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject of email");
emailIntent.putExtra(Intent.EXTRA_TEXT, "This is test app");
startActivity(emailIntent);
Not very clear what exactly you want. But if you need to add text/data in email body use
intent.putExtra(Intent.EXTRA_TEXT, "This data will appear in email body");
every time i create an action for sending an email from my app, it prompts to many options including a QR client...
Is there a way to force sending via email clients only?
Code for sending the email
String rec[] = { owner.email };
i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_EMAIL, rec);
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "RE: " + desc);
i.putExtra(android.content.Intent.EXTRA_TEXT,
"\n\n\nSent from Mojo for Android");
startActivity(i);
Screenshot for what happens when I launch this
Try to setType message/rfc822 instead of text/plain
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:"));
else use this it will shows only the mail clients,
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
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 think you should change the setType to
i.setType("message/rfc822") ;
Even though it's too late for #thepoosh, but it may be helpful for future questioners. After a lot of searching and testing, I finally found a good solution.
Thanks to the Open source developer, cketti for sharing his/her concise solution.
String mailto = "mailto:bob#example.org" +
"?cc=" + "alice#example.com" +
"&subject=" + Uri.encode(subject) +
"&body=" + Uri.encode(bodyText);
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse(mailto));
try {
startActivity(emailIntent);
} catch (ActivityNotFoundException e) {
//TODO: Handle case where no email app is available
}
This is the link to his/her gist.
It will show all the available app installed on android phone which can perform sharing or send a link from webview to others. Like - Gmail, facebook, imo, whatsapp, messenger etc.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
String shareLink = webView.getUrl();
intent.putExtra(Intent.EXTRA_TEXT, shareLink);
startActivity(Intent.createChooser(intent, "Share via..."));
But when you force to open mail app only :
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"something#gmail.com"});
try {
startActivity(Intent.createChooser(intent, "send mail"));
} catch (ActivityNotFoundException ex) {
Toast.makeText(this, "No mail app found!!!", Toast.LENGTH_SHORT);
} catch (Exception ex) {
Toast.makeText(this, "Unexpected Error!!!", Toast.LENGTH_SHORT);
}
As long as you are using ACTION_SEND with type text/plain, it will show all the valid options. However, if you want, you may design your your own dialog window which shows only Gmail or other mail client by doing filtering programatically.
BTW, why do you even need this window when you just want to use Gmail?
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("mailto:?to=email&subject=hello&body=hello%20world"));
startActivity(Intent.createChooser(intent, "Send via..."));
you can try this:::::
Intent.setType("plain/text");
At first when I spotted this I immediately though it was a mistake and it was meant to be text/plain, but this is actually the correct way to only display E-mail clients in the application list.
Give it a try and see for yourself.
intent.setPackage("com.google.android.gm"); //Added Gmail Package to forcefully open Gmail App
String rec[] = { owner.email };
i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822") ;
i.putExtra(android.content.Intent.EXTRA_EMAIL, rec);
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "RE: " + desc);
i.putExtra(android.content.Intent.EXTRA_TEXT,
"\n\n\nSent from Mojo for Android");
startActivity(i);
try this;:::
I just can't seem to get the e-mail sending working in Android.
Probably something stupid but I can't find it:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain")
.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "jb#mail.anykey.co.il" })
.putExtra(android.content.Intent.EXTRA_SUBJECT,"Exception in Yaniv!")
.putExtra(android.content.Intent.EXTRA_TEXT,"test");
ApplicationControllerBase.getMyApplicationContext().startActivity(Intent.createChooser(emailIntent,
"Send mail...").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
I am not getting any error or exception on the startActivity command.
=======
Edit:
Seems that this is the same problem as this guy is having: Android: How to start an activity from an UncaughtExceptionHandler set in application
setType should be plain/text
try with the following code
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"webmaster#website.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "mySubject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "myBodyText");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));