4

I'm using the following code to send emails with multiple attachments using M4A (should be easily transferable to Java):

                Intent intent = new Intent(Intent.ActionSendMultiple);
                intent.SetType("text/plain");
                intent.PutExtra(Intent.ExtraText, "Mail body");
                intent.PutExtra(Intent.ExtraSubject, "Mail subject");

                DirectoryInfo di = new DirectoryInfo(Android.App.Application.Context.FilesDir.AbsolutePath);
                List<Android.Net.Uri> fileList = new List<Android.Net.Uri>();
                foreach (FileInfo file in di.GetFiles("MyAppLogFile*"))
                { 
                    Java.IO.File myFile = new Java.IO.File(file.FullName);
                    var uri = Android.Net.Uri.FromFile(myFile);
                    fileList.Add(uri);
                }
                if (fileList.Count > 0)
                    intent.PutParcelableArrayListExtra(Intent.ExtraStream, fileList.ToArray());

                StartActivity(Intent.CreateChooser(intent, "Send email"));

This worked fine on ICS devices, but on Jelly Bean, the mail programm still shows the attachments, but they are not being sent. Since the files come from within the protected part of the file system belonging to the app, I suspect that something may have changed with the permission system from ICS (tried on a Galaxy S3) and JB (tried on a Galaxy S3 and Galaxy Nexus - the latter running JB 4.2).

Has anybody successfully managed to send emails with attachments on JB where the files to be sent are located in the application directory or a subdirectory thereof?

Thanks Stephan

Stephan Steiner
  • 1,043
  • 1
  • 9
  • 22
  • What is your target and minimum SDK versions? – Alex Wiese Nov 30 '12 at 00:23
  • targetSdkVersion: 15, mimimum sdk version: 15 – Stephan Steiner Dec 04 '12 at 20:24
  • By the way... I never posted my solution. It appears that Jelly Bean is more strict in enforcing file access... files that you write to your app's standard directory (/data/data/yourpackage/files) could be attached to a mail in ICS just fine (even though technically the mail client isn't allowed to access your app's private files), and on JB, this is now enforced. So I ended up copying the files I intend to mail to a publicly accessible directory. If you need to send something that's not meant to be shared, that may not be ideal, but in my case it doesn't matter – Stephan Steiner Sep 03 '13 at 16:43

0 Answers0