Question

I'm building an app that has the ability to send info in an email. When I click the send email button the phone's contact list is brought up and the email retrieved from the person chosen. Then depending on whether I choose to send via 'Gmail' or 'Hotmail' I get different results. For gmail the person's email address is placed in the 'from' field and pressing on the 'to' field does nothing. On the other hand, in hotmail, the retrieved email address ignores the '@hotmail.com' part (which I presume is actually in the 'to' field but there is no indication (although it is at the top!), and clicking 'send' results in an invalid email address message. Also clicking on the address does nothing. Here's my code for the sending:

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

emailIntent.setType("plain/text");
emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
System.out.println("email set as: " + email);
final String subject = diaryDetailedName + "'s diary entry ";
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
final String emailBody = "I have an entry in my diary that you should know about. " +
            "Its for " + detailedTitle + " which will involve " + detailedDesc + 
            ". This is on " + dDate + " at " + detailedTime + ". Please get in touch if you need to know more.";
emailIntent.putExtra(Intent.EXTRA_TEXT, emailBody);

DiaryDetailed.this.startActivity(Intent.createChooser(emailIntent, "Send mail in:"));

Any ideas? Thanks in advance!

Was it helpful?

Solution

I think you are supposed to pass string array as EXTRA_EMAIL

So , try making this

emailIntent.putExtra(Intent.EXTRA_EMAIL, email);

into

emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});

Reference:developer.android.com/reference/android/content/Intent.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top