Java – How to launch email intent with an attached image

androidjava

I am trying to launch an email intent with an attached jpg.

I did:

Intent intent4 = new Intent(Intent.ACTION_SENDTO,
Uri.fromParts("mailto", "testemail@gmail.com", null));
startActivity(intent4);

this launches the email activity.

But when I try to add DataAndType (my jpeg attachment). It fails with

android.content.ActivityNotFoundException: No Activity found to handle Intent { action=android.intent.action.SENDTO data=file:///data/data/com.mycompany.mypackage/files/temp-picture type=JPEG 


Intent intent4 = new Intent(Intent.ACTION_SENDTO,
  Uri.fromParts("mailto", "testemail@gmail.com", null));
intent4.setDataAndType(Uri.parse("file://"+ mTempFilePath),
  Bitmap.CompressFormat.JPEG.name());    
startActivity(intent4);

Best Solution

Did you try setting the mime manually to "image/jpeg" instead of Bitmap.CompressFormat.JPEG.name().