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
Related
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;:::
I'm trying to share some text using an intent:
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_TEXT, "TEXT");
and warping with chooser:
startActivity(Intent.createChooser(sms, getResources().getString(R.string.share_using)));
it works! but only for email app.
what I need is a general intent for all messaging app: emails, sms, IM (Whatsapp, Viber, Gmail, SMS...)
tried using android.content.Intent.ACTION_VIEW
and tried using i.setType("vnd.android-dir/mms-sms"); nothing helped...
("vnd.android-dir/mms-sms" shared using sms only!)
Use the code as:
/*Create an ACTION_SEND Intent*/
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
/*This will be the actual content you wish you share.*/
String shareBody = "Here is the share content body";
/*The type of the content is text, obviously.*/
intent.setType("text/plain");
/*Applying information Subject and Body.*/
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.share_subject));
intent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
/*Fire!*/
startActivity(Intent.createChooser(intent, getString(R.string.share_using)));
New way of doing this would be using ShareCompat.IntentBuilder like so:
// Create and fire off our Intent in one fell swoop
ShareCompat.IntentBuilder
// getActivity() or activity field if within Fragment
.from(this)
// The text that will be shared
.setText(textToShare)
// most general text sharing MIME type
.setType("text/plain")
.setStream(uriToContentThatMatchesTheArgumentOfSetType)
/*
* [OPTIONAL] Designate a URI to share. Your type that
* is set above will have to match the type of data
* that your designating with this URI. Not sure
* exactly what happens if you don't do that, but
* let's not find out.
*
* For example, to share an image, you'd do the following:
* File imageFile = ...;
* Uri uriToImage = ...; // Convert the File to URI
* Intent shareImage = ShareCompat.IntentBuilder.from(activity)
* .setType("image/png")
* .setStream(uriToImage)
* .getIntent();
*/
.setEmailTo(arrayOfStringEmailAddresses)
.setEmailTo(singleStringEmailAddress)
/*
* [OPTIONAL] Designate the email recipients as an array
* of Strings or a single String
*/
.setEmailTo(arrayOfStringEmailAddresses)
.setEmailTo(singleStringEmailAddress)
/*
* [OPTIONAL] Designate the email addresses that will be
* BCC'd on an email as an array of Strings or a single String
*/
.addEmailBcc(arrayOfStringEmailAddresses)
.addEmailBcc(singleStringEmailAddress)
/*
* The title of the chooser that the system will show
* to allow the user to select an app
*/
.setChooserTitle(yourChooserTitle)
.startChooser();
If you have any more questions about using ShareCompat, I highly recommend this great article from Ian Lake, an Android Developer Advocate at Google, for a more complete breakdown of the API. As you'll notice, I borrowed some of this example from that article.
If that article doesn't answer all of your questions, there is always the Javadoc itself for ShareCompat.IntentBuilder on the Android Developers website. I added more to this example of the API's usage on the basis of clemantiano's comment.
This a great example about share with Intents in Android:
* Share with Intents in Android
//Share text:
Intent intent2 = new Intent(); intent2.setAction(Intent.ACTION_SEND);
intent2.setType("text/plain");
intent2.putExtra(Intent.EXTRA_TEXT, "Your text here" );
startActivity(Intent.createChooser(intent2, "Share via"));
//via Email:
Intent intent2 = new Intent();
intent2.setAction(Intent.ACTION_SEND);
intent2.setType("message/rfc822");
intent2.putExtra(Intent.EXTRA_EMAIL, new String[]{EMAIL1, EMAIL2});
intent2.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
intent2.putExtra(Intent.EXTRA_TEXT, "Your text here" );
startActivity(intent2);
//Share Files:
//Image:
boolean isPNG = (path.toLowerCase().endsWith(".png")) ? true : false;
Intent i = new Intent(Intent.ACTION_SEND);
//Set type of file
if(isPNG)
{
i.setType("image/png");//With png image file or set "image/*" type
}
else
{
i.setType("image/jpeg");
}
Uri imgUri = Uri.fromFile(new File(path));//Absolute Path of image
i.putExtra(Intent.EXTRA_STREAM, imgUri);//Uri of image
startActivity(Intent.createChooser(i, "Share via"));
break;
//APK:
File f = new File(path1);
if(f.exists())
{
Intent intent2 = new Intent();
intent2.setAction(Intent.ACTION_SEND);
intent2.setType("application/vnd.android.package-archive");//APk file type
intent2.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f) );
startActivity(Intent.createChooser(intent2, "Share via"));
}
break;
Use below method, just pass the subject and body as arguments of the
method
public static void shareText(String subject,String body) {
Intent txtIntent = new Intent(android.content.Intent.ACTION_SEND);
txtIntent .setType("text/plain");
txtIntent .putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
txtIntent .putExtra(android.content.Intent.EXTRA_TEXT, body);
startActivity(Intent.createChooser(txtIntent ,"Share"));
}
Below is the code that works with both the email or messaging app.
If you share through email then the subject and body both are added.
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareString = Html.fromHtml("Medicine Name:" + medicine_name +
"<p>Store Name:" + “store_name “+ "</p>" +
"<p>Store Address:" + “store_address” + "</p>") .toString();
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Medicine Enquiry");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareString);
if (sharingIntent.resolveActivity(context.getPackageManager()) != null)
context.startActivity(Intent.createChooser(sharingIntent, "Share using"));
else {
Toast.makeText(context, "No app found on your phone which can perform this action", Toast.LENGTH_SHORT).show();
}
By Creating an Intent using ACTION_SEND you will be able to put extra its type is Intent.EXTRA_TEXT, the second argument is the text you want to share.
Then by setting the share type as text/plain, the Intent service will bring you all apps that support sharing text
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
Intent shareIntent = Intent.createChooser(sendIntent, null);
startActivity(shareIntent);
Images or binary data:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/jpg");
Uri uri = Uri.fromFile(new File(getFilesDir(), "foo.jpg"));
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri.toString());
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
or HTML:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/html");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<p>This is the text shared.</p>"));
startActivity(Intent.createChooser(sharingIntent,"Share using"));
Kotlin
Inside the click listener needed to add this module for sharing text via applications like whatsApp, email like Gmail, Slack..
shareOptionClicked.setOnClickListener{
val shareText = Intent(Intent.ACTION_SEND)
shareText.type = "text/plain"
val dataToShare = "Message from my application"
shareText.putExtra(Intent.EXTRA_SUBJECT, "Subject from my application")
shareText.putExtra(Intent.EXTRA_TEXT, dataToShare)
startActivity(Intent.createChooser(shareText, "Share Via"))
}
This code is for sharing through sms
String smsBody="Sms Body";
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", smsBody);
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
100 % Working Code For Gmail Share
Intent intent = new Intent (Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"anyMail#gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Any subject if you want");
intent.setPackage("com.google.android.gm");
if (intent.resolveActivity(getPackageManager())!=null)
startActivity(intent);
else
Toast.makeText(this,"Gmail App is not installed",Toast.LENGTH_SHORT).show();
I have a code the fires intent for sending email
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL,
new String[] { to });
i.putExtra(Intent.EXTRA_SUBJECT, subject);
i.putExtra(Intent.EXTRA_TEXT, msg);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Start.this,
"There are no email clients installed.",
Toast.LENGTH_SHORT).show();
}
But when this intent is fired I see many item in the list like sms app , gmail app, facebook app and so on.
How can I filter this and enable only gmail app (or maybe just email apps)?
Use android.content.Intent.ACTION_SENDTO (new Intent(Intent.ACTION_SENDTO);) to get only the list of e-mail clients, with no facebook or other apps. Just the email clients.
I wouldn't suggest you get directly to the email app. Let the user choose his favorite email app. Don't constrain him.
If you use ACTION_SENDTO, putExtra does not work to add subject and text to the intent. Use Uri to add the subject and body text.
Example
Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:" + Uri.encode("email#gmail.com") +
"?subject=" + Uri.encode("the subject") +
"&body=" + Uri.encode("the body of the message");
Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, "Send mail..."));
The accepted answer doesn't work on the 4.1.2. This should work on all platforms:
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","abc#gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "EXTRA_SUBJECT");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
Hope this helps.
Igor Popov's answer is 100% correct, but in case you want a fallback option, I use this method:
public static Intent createEmailIntent(final String toEmail,
final String subject,
final String message)
{
Intent sendTo = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:" + Uri.encode(toEmail) +
"?subject=" + Uri.encode(subject) +
"&body=" + Uri.encode(message);
Uri uri = Uri.parse(uriText);
sendTo.setData(uri);
List<ResolveInfo> resolveInfos =
getPackageManager().queryIntentActivities(sendTo, 0);
// Emulators may not like this check...
if (!resolveInfos.isEmpty())
{
return sendTo;
}
// Nothing resolves send to, so fallback to send...
Intent send = new Intent(Intent.ACTION_SEND);
send.setType("text/plain");
send.putExtra(Intent.EXTRA_EMAIL,
new String[] { toEmail });
send.putExtra(Intent.EXTRA_SUBJECT, subject);
send.putExtra(Intent.EXTRA_TEXT, message);
return Intent.createChooser(send, "Your Title Here");
}
This is quoted from Android official doc, I've tested it on Android 4.4, and works perfectly. See more examples at https://developer.android.com/guide/components/intents-common.html#Email
public void composeEmail(String[] addresses, String subject) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
Replace
i.setType("text/plain");
with
// need this to prompts email client only
i.setType("message/rfc822");
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","opinions#gmail.com.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "IndiaTV News - Mobile App Feedback");
emailIntent.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(Settings.this.getString(R.string.MailContent)));
startActivityForResult(Intent.createChooser(emailIntent, "Send email..."),0);