I am pretty stuck with Xamarin.Forms/Android at the moment, I need to download a csv file from a specific URL in the 'Download' directory of my phone, however I continuously get System.UnauthorizedAccessException: Access to the path "/storage/emulated/0/Download/myFile.csv" is denied.
public async Task DownloadAsync(string url)
{
try
{
using(var webClient = new WebClient())
{
var directoryPath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath;
string pathToNewFile = Path.Combine(directoryPath, myFile.csv);
await webClient.DownloadFileTaskAsync(new Uri(url), pathToNewFile);
}
}
catch(Exception ex)
{
throw;
}
}`
These are my permissions setup:
- INTERNET
- WRITE_EXTERNAL_STORAGE
- ACCESS_COARSE_LOCATION
- ACCESS_FINE_LOCATION
- READ_EXTERNAL_STORAGE
I cannot get it why it does not work. By the way I am testing on a physical device(Pixel3), maybe I shall set some configuration inside my phone... have no idea what's wrong here