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

前端 未结 5 1791
臣服心动
臣服心动 2020-12-06 16:52

So I\'m trying to create a file and I\'m getting System.UnauthorizedAccessException: Access to the path \"/DownloadJitters\" is denied. I\'m not sure if it\'s a permissions

5条回答
  •  不思量自难忘°
    2020-12-06 17:22

    First of all add this permissions to you Manifest:

    
    
    

    Since Android 6.0 (API 23) you need also to request the permissions manually, add this code on your MainActivity.cs on your Xamarin.Android project:

    if ((ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) != (int)Permission.Granted)
                || (ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) != (int)Permission.Granted))
            {
                ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.ReadExternalStorage, Manifest.Permission.WriteExternalStorage }, REQUEST);
            }
    

    Since Android 10 you may also need to add android:requestLegacyExternalStorage attribute to your Manifest like this:

    
    

提交回复
热议问题