2

I'm getting the UnauthorizedAccessException when starting up my emulator with my application, it tells me that "Access to /storage/emulated/0/Download/MenuPlayer is denied".

This only occurs when I try to create a file or open up a folder to download files into it.

My AndroidManifest.xml code is:

<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="26" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

My Code that is trying to access this is:

try {
    /// Get the path to the downloads folder
    var donwloadDir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads);
    path = Path.Combine(donwloadDir.AbsolutePath, dirName);
    dirInfo = new DirectoryInfo(path);
    ///Create a path to the config file folder.
    configFilePath = Android.OS.Environment.GetExternalStoragePublicDirectory("").AbsolutePath + "/";
} catch(Exception e) {
    Android.Util.Log.Debug(TAG, "STUFF HERE..." + configFilePath);
    Android.Util.Log.Debug(TAG, e.Message);
    System.IO.File.WriteAllText(@"C:\logs.txt", e.Message);
}
System.IO.File.WriteAllText(@"C:\logs.txt", Android.OS.Environment.DirectoryDownloads);
Android.Util.Log.Debug(TAG, configFilePath);
Android.Util.Log.Debug(TAG, "END | PlayerReader");

the error is:

Unhandled Exception:

System.UnauthorizedAccessException: Access to the path "/storage/emulated/0/Download/MenuPlayer" is denied. occurred
Pradip Tilala
  • 1,715
  • 16
  • 24

1 Answers1

0

Even if you have enabled READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permission in manifest, you might need to do few things explicitly in code. Are you doing that already?

See post below for details

Xamarin-System.UnauthorizedAccessException: Access to the path is denied

Hope this helps

user007
  • 540
  • 5
  • 11
  • Thanks for the response user007, I managed to sort it out, apparently all I had to do was to simply continue even after an error popped and then go enable storage permissions on the emulator. – Mzimhle Mosiwe Jul 09 '19 at 07:41