A Guide to Mobile and Web Technology(LAMP)

Archive for October, 2009

How to send a Email attachment or MMS in Android

The following lines of code are used to send a image as either mail attachment
or as MMS from the android mobile programatcally!


Intent sendIntent = new Intent(Intent.ACTION_SEND);
//Mime type of the attachment (or) u can use sendIntent.setType("*/*")
sendIntent.setType("image/jpeg");
//Subject for the message or Email
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "My Picture");
//Full Path to the attachment
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://sdcard/test.png"));
//Use a chooser to decide whether email or mms
startActivity(Intent.createChooser(sendIntent, "Email:"));

How to send Sms from Android Programatically

The following lines of code are used to send sms from android phones. This will launch the default sms intent with a message

“Hi this is test sms”

and allows to enter the phone number and edit the message if necessary!

//call the default intent to launch message compose page

Intent sendIntent = new Intent(Intent.ACTION_VIEW);
//use to fill the sms body
sendIntent.putExtra("sms_body", "Hi this is test sms"); 
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);