mono / taglib-sharp

Library for reading and writing metadata in media files
GNU Lesser General Public License v2.1
1.27k stars 312 forks source link

System.UnauthorizedAccessException Xamarin Forms #167

Open gitChef30 opened 5 years ago

gitChef30 commented 5 years ago

If you try to edit a file in an external storage it throws a System.UnauthorizedAccessException: Access to the path "/storage/4FAE-757R/Downloads/Audio.mp3" is denied.

This is the code:

            File file = File.Create(path);
            Tag tag = file.Tag;

            tag.Title = "Title test";
            tag.Performers = new string[1] { "Performer test" };

            file.Save();
            file.Dispose();

the exception is thrown right after the execution of the file.Save(); statement. No exception if the file is in the internal storage. Certainly, the _READ_EXTERNAL_STORAGE and the WRITE_EXTERNALSTORAGE permissions are present in the AndroidManifest.xml file.

grbrandt commented 3 years ago

@gitChef30 Which API version are you targeting? If 10 (Android Q), the exception is most likely caused by changes on how the platform works.

Try targeting API 9 or, set the property android:requestLegacyExternalStorage="true" in the applicationnode in AndroidManifest.xml