Tuesday, May 8, 2012

Android MMS Intent with with Image and body text

I am trying to create an intent that will start the MMS application for me with an image file attached and some pre-defined text present in the message body.



Thus far I've been able to accomplish either or, but not both at the same time.



Things I've tried (with their results):



sendIntent = new Intent(android.content.Intent.ACTION_SEND,Uri.parse("mms://"));
sendIntent.setType("image/gif");
sendIntent.putExtra(Intent.EXTRA_STREAM, imgStreamUri);
sendIntent.putExtra("sms_body", "HelloWorld");
startActivity(Intent.createChooser(sendIntent,"Send"));
/**********
Image file is attached but no text added to message body.
**********/

sendIntent = new Intent(android.content.Intent.ACTION_SEND);
sendIntent.setType("image/gif");
sendIntent.putExtra(Intent.EXTRA_STREAM, imgStreamUri);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "HelloWorld");
sendIntent.putExtra(Intent.EXTRA_TITLE, "WorldHello");
startActivity(Intent.createChooser(sendIntent,"Send"));
/**********
Image file is attached but no text added to message body(or subject or anything).
**********/


Does anyone know how I can attach both body text and an image file to an mms intent that will launch the default messaging application with the appropriate items filled in?



EDIT: Tested the code @lenik provided in answer. It is working on some devices, here's what I found



Works correctly:




  • Epic 4g (Galaxy S)

  • Epic 4g Touch (Galaxy S II)

  • Galaxy Nexus(ICS 4.0.4)

  • HTC Desire (Froyo 2.2)

  • Motorola Photon



Image attached but no text:




  • Sidekick 4g

  • Samsung Transform Ultra



Anyone know if I am basically s.o.l. on the devices that don't work properly this way?





No comments:

Post a Comment