I'm wanting to trigger an Email from my xml preferences screen and also attach a pre-defined subject and start the cursor in the Body field of the email application
Here's what I've got so far
<Preference
android:title="Support"
android:summary="Having a problem?">
<intent
android:action="android.intent.action.VIEW"
android:data="mailto:support@xxxxx.com"
/>
</Preference>
Works great for triggering the email intent, but how would i go about accomplishing the others via xml? attaching the subject and all?
You can use both mailto query parameters, as jondavidjohn says, and also intent extras, and you can mix and match them both. For example:
<intent
android:action="android.intent.action.VIEW"
android:data="mailto:xxxxx@xxxxxxx.com?subject=this is a test subject">
<extra android:name="android.intent.extra.TEXT" android:value="This is a test" />
</intent>
...will allow you to set the body of an email as well as the subject. You can also specify the subject as an extra. This lets you use XML string resources rather than hardcoding, too:
<extra android:name="android.intent.extra.SUBJECT" android:value="@string/email_subject" />
I just grabbed the Intent extra names from Intent.java; the email-related ones are all in a bunch together.
I've only just discovered this and haven't done much testing, but this certainly seems to work with my GMail mail client.
Also, if it's any help, I did have success using the "body" of the mailto: URI, e.g.
mailto:example@example.com?subject=This%20is%20a%20subject&body=This%20is%20a%20body
Don't know whether it helped that I url-encoded my mailto URL; I was just doing it through force of habit, coming from a web background. But that definitely works and sets a body in both GMail and K9 Mail apps.
Apparently you can use many of the querystring arguments that you can on the normal browser mailto: uri.
So to accomplish this you just have to use them like this.
<intent
android:action="android.intent.action.VIEW"
android:data="mailto:xxxxx@xxxxxxx.com?subject=this is a test subject"
/>