Android – Sending email attachment android with intent. Only works in Gmail

androidandroid-intentemailemail-attachmentsxamarin.android

I am trying to send a .png file with an Android intent. I have tried saving this file in internal storage with WorldReadable permissions and now have saved to the external storage. When I open the GMail client my attachment is there. However, in Microsoft Exchange or Outlook app the attachment does not appear and I have to add it manually.

I'm using Xamarin.Android (MonoDroid) but any java solutions would be helpful as well.
Here is my code for sending the email with the intent.

        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setType("image/png"); // I also tried 'application/image'
        intent.setData(Android.Net.Uri.Parse("mailto:" + address ?? string.Empty));

        if (!string.isNullOrEmpty (attachment)) {
            intent.putExtra (Android.Content.Intent.EXTRA_STREAM, Android.Net.Uri.fromFile(new Java.IO.File (Android.OS.Environment.getExternalStorageDirectory(), attachment)));
        }

        try {
            _Context.startActivity(intent);
        }catch(ActivityNotFoundException anfe) {

            //Show prompt
        }

I'm not sure why the attachment only shows up in GMail. Do I need a content provider? It's weird that its only showing up in GMail and not any other mail applications.

Best Answer

You shouldn't need a ContentProvider.

I'm doing the basically the same thing for sending a JPEG, but using Intent.ActionSend instead of Intent.ActionSendTo.

Related Topic