Sending mails on HTC Hero

I wanted to create an automatically crash report feedback in SqueezeCommander.

I thought, the easiest solution would be to send the reports by mail, so the user can also see all informations that will be reported to me and choose if he wants to send or discard the report.

Normally, it should be possible to send emails from within an application by creating an intent Intent.ACTION_SEND with extra parameters.

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "email text");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"email@address.com"});
sendIntent.setType("message/rfc822");
startActivity(Intent.createChooser(sendIntent, "Title:"));

Unfortunately, this does not work on my HTC Hero. ;-(

After some debugging, I found the reason:

HTC has implemented an own mail client (com.htc.android.mail) and it seams that this mail clients does not register correctly for Intent handling.

Therefore, the mail will be delivered to the internal Android Mail client (com.android.email), but that one is normally not configured (it does not share the settings with HTC Mail). :-(

I was able to make it work by using “text/plain” as message type:

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "email text");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"email@address.com"});
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Title:"));

Using this code, a chooser is shown to the user that also includes HTC Mail.

Unfortunately, even this solution does not work 100%, because if the user selects HTC Mail, the receiver address is not inherited. :-(

I’m still searching for a working solution…

For the crash reports, I’ve now set up a PHP script on my server that receives the crash report via POST request from my Android users and forwards it to me by email.

If you like my work, buy me a beer. (Suggested: 3€ for a beer, or more for more beer ;-) )

Tags: ,

4 Responses to “Sending mails on HTC Hero”

  1. gabe says:

    Hi,

    I’m facing with the same problem. Did you find solution for populating to field in the HTC e-mail client?

    Thanks in advance.

    G.

  2. flattermann says:

    Unfortunately, no. :-(

    I think this is a bug in the HTC mail implementation…

  3. gabe says:

    I found a workaround that is not perfect but a bit better on HTC. You can create a “mailto:” uri from the to, subject, and body of the email, and open it with ACTION_VIEW intent. First of all the phone will offer only e-mail client, you can select default client (to avoid selector next time), and the to field is working in GMail and HTC mail client too. The only issue is that the HTC Mail client is not able to handle end-of-line characters in this case. So you have to send one line text in body.
    Here you can find example code: (see method “sendEmail()) http://code.google.com/p/bankdroid/source/browse/trunk/bankdroid.soda/src/bankdroid/soda/SMSListActivity.java?spec=svn77&r=77

    There is an other known issue that the K-9 e-mail client is not able to handle this type of Intent at all. I’ve already opened a ticket for them.

  4. chris says:

    Thanks gabe – your code sample worked flawlessly.

Leave a Reply