You are here

Send data to someone

Action: 
android.intent.action.SEND
Action (WebIntents): 
http://webintents.org/share
Input: 
type of the intent is the MIME type of the data being sent. get*Extra can have either a EXTRA_TEXT or EXTRA_STREAM field, containing the data to be sent. If using EXTRA_TEXT, the MIME type should be "text/plain"; otherwise it should be the MIME type of the data in EXTRA_STREAM. Use */* if the MIME type is unknown (this will only allow senders that can handle generic data streams). Optional standard extras, which may be interpreted by some recipients as appropriate, are: EXTRA_EMAIL, EXTRA_CC, EXTRA_BCC, EXTRA_SUBJECT.
Output: 
None

Deliver some data to someone else.

Who the data is being delivered to is not specified; it is up to the receiver of this action to ask the user where the data should be sent.

This intent is described originally at http://code.google.com/android/reference/android/content/Intent.html#ACT...

Status of intents protocol: 

Comments

See the discussion on MIME types for mail.


Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "email text");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
sendIntent.setType("message/rfc822");
startActivity(Intent.createChooser(sendIntent, "Title:"));

To send a file attachment from the SD card use the following code:

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("audio/mp3");
sendIntent.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(sendIntent, "Title:"));

setType should set the MIME type of the file being sent.
A list of commonly used extensions and corresponding MIME types is included in the OI File Manager mimetypes.xml.

PS: In your application, you can easily obtain the file name by calling the PICK FILE intent of the OI File Manager.

For the built-in MMS application, the following undocumented extras may be useful:

See current source code:
http://android.git.kernel.org/?p=platform/packages/apps/Mms.git;a=blob;f...

mExternalAddress = intent.getStringExtra("address");
mExitOnSent = intent.getBooleanExtra("exit_on_sent", false);
mMsgText = intent.getStringExtra("sms_body");
String subject = intent.getStringExtra("subject");

As mentioned in this Stack Overflow thread, files have to be attached as sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/mysong.mp3"));
You need the extra / in file:/// (missing in the Stack Overflow post) as otherwise GMail drops the attachment just before sending stating the file path is wrong.