Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Permission error on Gmail 5.0 #116

Open
dlpopescuw opened this issue Jun 28, 2016 · 2 comments
Open

Permission error on Gmail 5.0 #116

dlpopescuw opened this issue Jun 28, 2016 · 2 comments

Comments

@dlpopescuw
Copy link

dlpopescuw commented Jun 28, 2016

Steps to reproduce

  1. Try to attach an image to a Gmail using the email plugin v 4.0.0
  2. Eror is thrown after choosing Gmail for sharing the pictures

Expected behavior

Images should be shown inside email's body

Actual behavior

Gmail throws an error "Permission denied for attachments"

Configuration

Version: 4.0.0

Platform: Android

@dlpopescuw
Copy link
Author

dlpopescuw commented Jun 28, 2016

TEMP WORKAROUND:

  1. Create a method ComposeEmail with the same signature as the method of the MvxComposeEmailTask class, inside the Android fragment

  2. Inside the method, replace this code:

        _if (attachments != null)
        {
            var uris = new List<IParcelable>();
    
            DoOnActivity(activity => {
                foreach (var file in attachments)
                {
                    File localfile;
                    using (var localFileStream = activity.OpenFileOutput(
                        file.FileName, FileCreationMode.WorldReadable))
                    {
                        localfile = activity.GetFileStreamPath(file.FileName);
                        file.Content.CopyTo(localFileStream);
                    }
                    localfile.SetReadable(true, false);
                    uris.Add(Uri.FromFile(localfile));
                    localfile.DeleteOnExit(); // Schedule to delete file when VM quits.
                }
            });
    
            if (uris.Any())
                emailIntent.PutParcelableArrayListExtra(Intent.ExtraStream, uris);
        }_
    

with this one:

        _if (message.attachments != null)
        {
            Mvx.Resolve<IMvxMainThreadDispatcher>().RequestMainThreadAction(() =>
            {
                foreach (var file in message.attachments)
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        var fileName = System.IO.Path.GetFileNameWithoutExtension(file.FileName);
                        var extension = System.IO.Path.GetExtension(file.FileName);

                        var newFile = Java.IO.File.CreateTempFile(fileName, extension, Context.ExternalCacheDir);
                        this.tempFiles.Add(newFile.AbsolutePath);

                        file.Content.CopyTo(memoryStream);
                        var bytes = memoryStream.ToArray();
                        using (var localFileStream = new FileOutputStream(newFile))
                            localFileStream.Write(bytes);

                        newFile.SetReadable(true, false);
                        newFile.DeleteOnExit();
                        uris.Add(Uri.FromFile(newFile));
                    }
                }
            });

            if (uris.Any())
                emailIntent.PutParcelableArrayListExtra(Intent.ExtraStream, uris);
        }_

where file.FileName is actually the file path
3. Inside the PCL, instead of calling Mvx.Resolve().ComposeEmail[...]: send a custom message, which contains the parameters required by the method, to the Android fragment via the MvxMessenger
4. At the reception of the message, execute the method ComposeEmail
5. Delete the temp files inside OnActivityResult, just to make sure they do not exist anymore

@g0rdan
Copy link
Contributor

g0rdan commented Jul 24, 2016

Hello, @dlpopescuw !
I'm trying reproduce a bug, but i can't. In my case, image perfectly attached to email.
Plugin version - 4.2.2
Android 5.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants