I am trying to use an intent to send an email from my application but the To field of the email will not populate. If I add code to fill in the subject or text, they work fine. Just the To field will not populate.
I have also tried changing the type to "text/plain" and "text/html" but I get the same problem. Can anyone help please?
public void Email(){
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("message/rfc822"); //set the email recipient
String recipient = getString(R.string.IntegralEmailAddress);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL , recipient);
//let the user choose what email client to use
startActivity(Intent.createChooser(emailIntent, "Send mail using...")); }
The email client I'm trying to use is Gmail
In Kotlin - Android
I hope this code snippet will help to kotlin developers.
I think you are not passing
recipient
asarray of string
it should be like
Use this
This will work :)
This is what android documentation says about Intent.Extra_Email
-A string array of all "To" recipient email addresses.
So you should feed string properly You can read more over here
http://developer.android.com/guide/components/intents-common.html#Email and here http://developer.android.com/guide/topics/resources/string-resource.html Or use the ACTION_SENDTO action and include the "mailto:" data scheme. For example:
Couple of things:
1 - You need to set the action constant variable as ACTION_SENDTO.
Intent intentEmail = new Intent(Intent.ACTION_SENDTO);
2 - If you want it to be opened by only the mail then use the setData() method:
intentEmail.setData(Uri.parse("mailto:"));
Otherwise it will ask you to open it as text, image, audio file by other apps present on your device.3 - You need to pass the email ID string as an array object and not just as a string. String is: "name@email.com". Array Object of the string is: new String[] {"email1", "email2", "more_email"}.