I have the following problem:
I am sending an email via an intent and in the email I want to have linebreaks.
When I try "setType('text/plain')" and use \n's the Email-App doesn't use these, but the Gmail-App is OK.
When I set "setType('text/html')" and use br's and Html.fromHtml(emailtext), the Email-app doesn't do line breaks. When I am not using Html.fromHtml(emailtext) the Email-app makes linebreaks, but the Gmail-App displays the br's as normal text.
Isn't there a way to do simple linebreaks in Android email intents?
hi, may b this code will help u out
String emailMessage = "<html><body><div align='left'><p>I found this information on Actor Genie and wanted to share it with you.</p><p><b>Feature </b>: "
+ filmName
+ "</p><p><b>Casting Director</b>: "
+ casting
+ "</p><p><b>Distributor</b>: "
+ distributor
+ "<p><b>Story Line</b>: "
+ storyLine
+ "</p><p>For up to the date casting info get <a href='http://www.actorgenie.com/'>Actor Genie</a></p></div></body></html>";
Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
// emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "");
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
emailSubject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html
.fromHtml(emailMessage));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Force Gmail by this
Intent emailIntent = new Intent(Intent.ACTION_VIEW);
emailIntent.setClassName("com.google.android.gm",
"com.google.android.gm.ComposeActivityGmail");
startActivity(emailIntent);
Use \n in your text code.
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hello \n World");
Related
On Android, Im implementing a button in order to open a mailbox. When a click on this button, a pop-in appear with installed mailbox but I see suggested contact.
Someone knows how to remove this contacts ? I want to see only mailbox.
Screenshot :
My intent configuration code :
// basic information
String body = "hello"
String recipientsList[] = { "hello#hello.com"};
String subject = "subject"
// configure intent to open maibox
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setType("message/rfc822");
// configure new email
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipientsList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
emailIntent.setData(Uri.parse("mailto:"));
Thanks !
EDIT - RESOLVED : Just using code below to launch mailbox solve the problem (but modify appearance of selector)
startActivity(emailIntent);
Try the following
String subject = "Feedback";
String bodyText = "Enter text email";
String mailto = "mailto:bob#example.org" +
"?cc=" + "" +
"&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
}
output:
I am experiecing "This action is not currrently supported" error condition when execute the following code snippet in Android 2.1. What is wrong with the snippet?
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
Uri uri = Uri.parse("mailto:myemail#gmail.com");
intent.setData(uri);
intent.putExtra("subject", "my subject");
intent.putExtra("body", "my message");
startActivity(intent);
}
If you use ACTION_SENDTO, putExtra() does not work to add subject and text to the intent. Use setData() and the Uri tool add subject and text.
This example works for me:
// ACTION_SENDTO filters for email apps (discard bluetooth and others)
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"));
Actually I found a way where the EXTRAs work.
This is a combination of an answer I found here regarding ACTION_SENDTO
http://www.coderanch.com/t/520651/Android/Mobile/no-application-perform-action-when
and something for HTML which I found here:
How to send HTML email
(but the variant of how to use ACTION_SENDTO in this HTML post didn't work for me - I got the "action not supported" which you are seeing)
// works with blank mailId - user will have to fill in To: field
String mailId="";
// or can work with pre-filled-in To: field
// String mailId="yourmail#gmail.com";
Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
Uri.fromParts("mailto",mailId, null));
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject text here");
// you can use simple text like this
// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Body text here");
// or get fancy with HTML like this
emailIntent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
.append("<p><b>Some Content</b></p>")
.append("<a>http://www.google.com</a>")
.append("<small><p>More content</p></small>")
.toString())
);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
You Can Try This One
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", emailID, null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT,
Subject);
emailIntent.putExtra(Intent.EXTRA_TEXT,
Text);
startActivity(Intent.createChooser(emailIntent, Choosertitle);
It Works For me
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 have a textbox(EditText) in my app & a button, what i want to do is that when anyone tap the button, the text written in the textbox(EditText) get copied & this text can be shared to any of the app such as - Messaging, Gmail, Ymail, etc.
Now What i am doing is getting the text from the "EditText" & storing it into a new variable (string) say 'a' & now applying the Intent "ACTION_SEND_MULTIPLE"
Here is the CODE for Intent
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"example#gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "a");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, a);
startActivity(Intent.createChooser(emailIntent, "Share it via..."));
I'm not sure what your problem is, but this is how you get text from an editText
String mString= et.getText().toString();
Then put it in the share intent
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, mString);
shareIntent.setType("text/plain");
startActivity(shareIntent);
If you want to send it as an email only, and only allow email clients to respond to the intent, it goes something like this.
Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:" + Uri.encode("mail to address")
+ "?subject=" + Uri.encode("subject here")
+ "&body=" + Uri.encode("body here");
Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, "Send..."));
This allows you to enter the subject field & mailto field...etc
You need "createChooser" maybe:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, edittext.getText().toString());
startActivity(Intent.createChooser(intent, "chooser title"));
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;:::