0

Hi i have problem with permission(i think). Im trying to download a file from Mega.nz by MegaApiClient and when it trying to do that that problem appears: "System.UnauthorizedAccessException: Access to the path '/storage/emulated/0/Download' is denied."

so i was trying different ways to do that like changing path folder or just simple create new file and write all content to that new file but nothing works. of course i have permission added in AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
<usespermissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 var client = new MegaApiClient();
 client.LoginAnonymous();
 Uri fileLink = new Uri(Link);
 INodeInfo node = client.GetNodeFromLink(fileLink);
 client.DownloadFile(node, node.Name); //problem occurs here 
 client.Logout();
  • Is this helping? https://stackoverflow.com/questions/46911486/xamarin-system-unauthorizedaccessexception-access-to-the-path-is-denied – Renat Apr 21 '19 at 19:39

2 Answers2

0

The problem probably occurs since your device / emulator on which you test your App has API 23 or higher. This means that the manifest permissions are not enough and you need to add runtime permissions asking for writing files.

This link will explain it using xamarin and this is the official documentation.

A runtime permission basically displays the user a dialog which lets him decide whether or not the App is allowed to access for instance the internal storage of the device.

Oh and this article will also help you implementing it.

Rene Ferrari
  • 4,096
  • 3
  • 22
  • 28
  • ive added some code to check if permission is granted ```if (ContextCompat.CheckSelfPermission(Application.Context, Manifest.Permission.WriteExternalStorage) == (int)Permission.Granted) client.DownloadFile(fileLink, node.Name);``` but in the same line of code the same problem appears – Jakub Stegienko Apr 22 '19 at 10:56
0

I think that you are writing to internal memory not external.

On the new Android you need to make the user accept the permission. So there most be a warning popup to allow write permission, location, etc.

Also you may try this: Android Dev Console support

Guille Bauza
  • 118
  • 4
  • anyways if user allow to write/read and i check if permission is granted still i cant download to my phone with sdk 27 @Guille Bauza – Jakub Stegienko Apr 22 '19 at 12:08