I am supporting an Android app written in Xamarin which has a feature where the user can email logs and SQLite db file to a support email address. It does this by zipping up the files and then copying the ZIP to the public Downloads folder, then attaching them to an email. It uses the Download folder so that other apps have permission to access the files, and I can see them if I connect to my PC with a USB cable.
This has worked fine until now - to deploy an update to the Play Store I now have to target API 29 and this no longer works. The function to move the ZIP file to the Download folder fails.
I use the following method to get the path to the new file in the download folder:
var path = Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath, filepath);
although VS is showing this method as obsolete:"deprecated"
When I try and move the ZIP file to it, I get
System.UnauthorizedAccessException: Access to the path "/storage/emulated/0/Download/logs.zip" is denied.
I have added
android:requestLegacyExternalStorage="true"
to my manifest, which has made no difference at all.
If I switch back to targeting API 28, all works fine.
Is there anywhere at all I could put the file to allow the user's default email app to read it as an attachment?
If you have requested for the read and write runtime permissions. Check the suggestions is the link below. Android 9.+ API 29: /storage/emulated/0/Pictures/myPic.png open failed: EACCES (Permission Denied)
And use the code below to replace the deprecated method.
var path = Path.Combine(GetExternalFilesDir(Android.OS.Environment.DirectoryDownloads).AbsolutePath, filepath);