简体   繁体   中英

System.UnauthorizedAccessException Why

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();

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM