0

I am trying to send a photo through MMS message, I am using the following known snippet

Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, "This is an MMS message");
String sendfilepath = "file://" + sendfile.toString() + ".jpg";
i.putExtra(Intent.EXTRA_STREAM,Uri.parse(sendfilepath)) ;
i.setType("image/jpeg");

It works with my Sony device. The pop up menu shows the messaging app along with other apps. But with HTC it does not show the Messaging app. It shows Bluetooth, Facebook, Mail, etc. How can I make it show the Messaging app in the "Complete action using" list

yasserbn
  • 391
  • 3
  • 18

1 Answers1

0

You can use this technique to check for HTC sense device and react appropriately to send the proper "version" of the intent.

Uri uri = Uri.fromFile(imgFile);
//HTC Sense intent
Intent sendIntent = new Intent("android.intent.action.SEND_MSG");
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("image/"+type);
List<ResolveInfo> resolves = getPackageManager().queryIntentActivities(sendIntent,PackageManager.MATCH_DEFAULT_ONLY);
if (resolves.size() > 0) {
    // This branch is followed only for HTC 
    startActivity(sendIntent);
} else {
    // Else launch the non-HTC sense Intent
    sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
    sendIntent.setType("image/"+type);
    startActivity(Intent.createChooser(sendIntent,"Send"));
}
FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • It opens the Messaging app but it does not attach the image. What do you mean by the +type? I put (image/jpeg) is it wrong? – yasserbn Jul 23 '12 at 22:01
  • it will be whatever type of file your image is, in my app I had some images of different types (png, jpeg etc) so I had to make that dynamic. If you only have jpegs, then you should be able to use `"image/jpeg"` – FoamyGuy Jul 24 '12 at 00:37