Wednesday, December 10, 2008

Sending MMS with Android

Following on from my last post about saving a view as an image, today I want to demonstrate how to send this image via MMS. We used this technique in our application, PinPoint to send out maps via MMS. 

I have previously written about how to send SMSs with Android intents and while sending MMS via intents goes to the same application, the intent that needs to be constructed is quite different. The intent requires the following items to be set:
  • the action set to be ACTION_SEND
  • the mime type set to image/*
  • a Uri extra inserted with the key Intent.EXTRA_STREAM
  • optionally some text body with the key sms_body
Intent sendIntent = new Intent(Intent.ACTION_SEND); 
sendIntent.putExtra("sms_body", "some text"); 
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
sendIntent.setType("image/png"); 

The url being passed to the Uri.parse method should be of the form used to access the media store such as content://media/external/images/media/23. The previous article of views and images returns a url String that can directly be used by this MMS intent. 

15 comments:

Keith said...

This works for me, except that the image is automatically converted to a jpeg, and fairly badly compressed at that. What's going on? I want an uncompressed png.

Thanks.

Blake B. said...

Thanks for the blog entry. I'm trying to do the same thing as you have shown, but with an audio file (.amr). However, when I use MIME type "audio/amr" or "audio/*", the Gmail client comes up. When I use "*/*", I get the MMS Compose Message window, but it gives an error message: "Unsupported picture format. Please select a different picture.":

final Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra("sms_body", msgText);
i.putExtra(Intent.EXTRA_STREAM, audioUri);
i.setType("*/*"); // audio/amr or audio/* goes to Gmail
startActivity(i);

Any ideas? How can I direct the system to create an MMS message with a .amr attachment?

txttools techies said...

Does this just pass the data to the Mms app' and open up the messaging activity, does the user then have to manually send the Mms message?

If so, do you know how it's possible to it programatically

Daniel Bradby said...

It opens up the messaging app with image attached ready for the user to select the receipient and send.

You could send it programatically but you would probably need to look deep within the messaging application code.

Start here -

http://android.git.kernel.org/?p=platform/packages/apps/Mms.git;a=tree;h=refs/heads/master;hb=master

good luck!

Domenico said...

sorry,
where i have to put the intent code?

nikhil said...

Hi, i am new to android. i tried to use your code but my application is showing error : application has stopped unexpectedly and is asking to force close. Can u pleaseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee help. i am writing below the entire code which i have used.
package com.nikhil.mms;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;

public class mms extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);
Intent intent = new Intent("android.intent.action.SEND_MSG");

intent.putExtra("address", "9999786766");
intent.putExtra("sms_body", "user_location");

// Uri uri = Uri.fromFile("/sdcard/dcim/camera/off2.jpg");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/dcim/Camera/off2.jpg")); // imageUri
// set
// previously
intent.setType("image/jpeg");

startActivity(intent);



}
}

in set of permissions i have added:
RECEIVE_SMS">








plz reply

nikhil said...

.RECEIVE_MMS">

nikhil said...

send sms, receive mms, read/write_owner_data, acccess_network_state

leeza said...

Even i am not able to send MMS from one emulator to another emulator.I tried the above mention code with proper permission set into manifest file but still not getting success. Can any one help me please...

Joel said...

How would I extract the subject, sender and URL from the PDU if I received the PDU from a receiver and recomposed using createFromPdu((byte[])pdus[i]); It seems very specific to SMS Messages and I am trying to figure out how to get the data for a MMS message like the Content_Location (URL), etc. Please Help ....

Fight for bright said...

Hello All,

I am new to android development,i am developing an application which needs to play music file when call is running, the callee has to hear the song, once playing audio is completed the call should be disconnected automatically...

so please help me how to do this..i am not getting any idea to do ...please do reply

thank you in advance....

Priya said...

Sending MMS got tether exception
Also SendTransaction failed got IOException. Is there any special providers needed for sending MMS in android phone??

Please Help me with valuable suggestions!!

Thanks

ii3_2010 said...

Hello everybody,
I'm new in the world of android and i'm developping an application that uses mms
as fonctionality!! i have to develop my classes for sending mms and not using
intent to switch for other application, does anybody have an idea how this works
on android.

Thanks

emi_me said...

hey check this new website www.countcode.com. It's a social network made for programmers, where you can download,share or upload source codes, where you can count your own code lines for free. You have access to the web forum and the web chatroom. we are happy to have you joined to our community!

Sanjay Bhansali said...

Any One Has An Example Of Voice Chatting...?? Pls Help Me.....