So I'm trying to launch a prepopulated email client with data. The content gets populated fine, however my problem is that when launching the intent, I wanted it to only show email clients to select from.
Instead, it shows Gmail, Adding to EverNote, Android Beam, Bluetooth, and some others.
I don't know if its an issue with lollipop that broke this functionality or not, as one of my managers sent me code that worked fine for him a few years ago.
My code is:
private void openEmailClient(){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{getResources().getString(R.string.contact_feedback_email_address)});
intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.contact_feedback_email_subject_android));
try{
startActivity(Intent.createChooser(intent,intentEmailString));
} catch(android.content.ActivityNotFoundException ex){
Log.e(EMAIL_FAIL_TAG, EMAIL_FAIL);
ex.printStackTrace();
}
}
when you will change your intent.setType like below you will get
intent.setType("text/plain");
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.
We can use message/rfc822 instead of "text/plain" as the MIME type. However, that is not indicating "only offer email clients" -- it indicates "offer anything that supports message/rfc822 data". That could readily include some application that are not email clients.
message/rfc822 supports MIME Types of .mhtml, .mht, .mime
EDIT
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:someone#example.com"));
intent.putExtra("subject", "my subject");
intent.putExtra("body", "my message");
startActivity(intent);
its working ...
So I solved it. Not ideally but it works better than anything else I have tried.
I followed the google docs on doing it, which says to do this:
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);
}
}
and it now works.
This just finds a default app for handling mail. I'm not sure how it decides, but in my case it opened GMail. On a device without GMail installed, such as the Galaxy S5, it opened their mail client and prompted the user to set up email.
Doesn't give choice of app but it works
Try like this it working fine for me...
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:abc#gmail.com"));
intent.putExtra(Intent.EXTRA_SUBJECT, "Test App");
intent.putExtra(Intent.EXTRA_TEXT, "Email Body");
startActivity(intent);
Note: it only work if you have email address.
For more information please refer this link Android - Is there a foolproof way to only show possible EMAIL clients?
Related
Part of my application functionality is to automatically fill gmail message subject, text, recipients and attach a photo. But I don't want to save this message as draft when I exit gmail intent without sending out the message.
How can I disable saving a draft before starting intent from my application? Is there a possible solution or workaround?
My intent code:
// fill email message fields for sending out report
public void composeEmail(String[] addresses, String subject) {
File filelocation = new File(mCurrentPhotoPath);
Uri photoUri = Uri.fromFile(filelocation);
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_STREAM, photoUri);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
Part of my application functionality is to automatically fill gmail message subject, text, recipients and attach a photo.
Your code has nothing specific to do with Gmail. There are many email clients for Android, and not everybody uses Gmail.
How can I disable saving a draft before starting intent from my application?
Write your own email client, rather than delegating to an existing email client. Otherwise, the decision of what goes on inside that email client is up to the user and the developers of that email client, not you.
I've implemented a class that can send a mail. However, you can only write a topic and the message and when you click on "Send" you've to choose which app (Outlook or Gmail) you want to send the mail with and then write your e-mail. However, I want to make it possible for the user to send a mail directly from the my app instead of using another app. So I want to make it possible for the user to write his/her e-mail/gmail and message and then send the message to my e-mail. So in other words in the fragment I want an EditText where the user writes his/her e-mail/gmail, another EditText where the user writes the message and a button to send. How can this be implemented?
This is what I have done in my app to send a mail:
private void sendemail(String message) {
String [] reciever = new String[]{"myemail#hotmail.com"};
String subject = ("Feedback/Question");
Intent mailIntent = new Intent(Intent.ACTION_SEND);
mailIntent.putExtra(Intent.EXTRA_EMAIL, reciever);
mailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
mailIntent.putExtra(Intent.EXTRA_TEXT, message);
mailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(mailIntent, "Choose an application to send your mail with"));
}
Use this library -> Send email in background. It will send an email from your app without users interaction.
Cheers!
using java mailApi,you must have to authenticate gmail app using credential.
please check this link:
Email via Java MailAPI
other link to provide custom class to send mail programatically.
https://stackoverflow.com/a/4345084/1223291
I hope its useful to you.
Use this method....
public void sendEmail()
{
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"care#xyz.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "care Feedback");
intent.putExtra(Intent.EXTRA_TEXT, "");
startActivity(Intent.createChooser(intent, "Send Email"));
}
ShareActionProvider provides share for every compatible app on the device. I would like to specify which apps I want to allow sharing, like only twitter and gmail for example.
How would I do this?
Google don't recommend that you share to specific apps as there are various different Twitter clients - it's better to just let people chose where they want to share it.
However, the following code will send the message "hello twitter" to twitter on a button press.
String message = "hello Twitter";
try {
//try to open the official twitter app
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(
android.content.Intent.EXTRA_SUBJECT, "Subject");
sharingIntent.putExtra(Intent.EXTRA_TEXT, message);
sharingIntent.setPackage("com.twitter.android");
startActivity(sharingIntent);
} catch (Exception e) {
//fallback on opening an internet browser
Log.e("Danielle", "exception=" + e.toString());
Intent i = new Intent();
i.putExtra(Intent.EXTRA_TEXT, message);
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri
.parse("https://mobile.twitter.com/compose/tweet"));
startActivity(i);
}
Hope that helps.
If you are ok with just using a popup, the answer by dacoinminster in this question How to filter specific apps for ACTION_SEND intent (and set a different text for each app) will do it.
But if you specifically want it to be an actionprovider dropdown, I have not find this solution either.
I am currently working on an android project and I am adding a preference to be able to send me an email. I am using the ACTION_SENDTO intent to send the email but its coming back and says No apps can perform this action.
Below is the code I am using
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, "someone#example.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Check out this android app");
intent.putExtra(Intent.EXTRA_TEXT, "Check out this new app in the Google Play Store. Its from Boardies IT Solutions and is called Boardies Password Manager. You can find it at https://play.google.com/store/apps/details?id=com.BoardiesITSolutions.PasswordManager");
startActivity(Intent.createChooser(intent, "Send Email"));
Thanks for any help you can provide
You need to add the following
intent.setData(Uri.parse("mailto:" + "email#bla.com")); // leave
blank if not specificity
I think you should replace Intent.ACTION_SENDTO to Intent.ACTION_SEND,
Hope this will work for you.
How about this code:
final Intent emailLauncher = new Intent(Intent.ACTION_SEND);
emailLauncher.setType("message/rfc822");
emailLauncher.putExtra(Intent.EXTRA_EMAIL, "username#domain.com");
emailLauncher.putExtra(Intent.EXTRA_SUBJECT, "check this subject line");
emailLauncher.putExtra(Intent.EXTRA_TEXT, "hey check this message body!");
try{
startActivity(emailLauncher);
}catch(ActivityNotFoundException e){
}
I want to send an email with android 2.2. First I made an intent chooser with an ACTION_SEND to select which to use :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, Resources.getString("EmailInvitationSubject", getBaseContext()));
String body = Resources.getString("EmailInvitationBody", getBaseContext()) + Local.User.FirstName;
intent.putExtra(Intent.EXTRA_TEXT, body);
startActivity(Intent.createChooser(intent, "Invite friends"));
But in that case, the selector show 'Bluetooth, Messaging, Google+, Gmail'. I want to show ONLY Gmail or other email app.
I saw in the sdk docs there's a new CATEGORY_APP_EMAIL to use but it's only available in the API level 15. I have to keep API level 8. Is there a way to do that ?
By the way, I'll want to do it for messaging too so that in the end I can have 2 buttons: one for email and one for messaging.
This code will shows only the email clients,
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"youremail#yahoo.com"});
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "message");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
You might want to checkout following (to get what you are looking at the end, i.e. "....By the way, I'll want to do it for messaging too so that in the end I can have 2 buttons: "):
http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android
or also you could checkout:
Android email chooser
Kind regards,
Bo