我尝试在android内部存储器中创建一个文件夹,但是当我统一构建一个应用程序然后在android上运行一个应用程序后,出现异常:
“对路径的未经授权的访问例外访问被拒绝”
void Start()
{
//Create cashe
AddCacheAtPath("cashe");
}
private void AddCacheAtPath(string path)
{
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
Cache newCache = Caching.AddCache(path);
//Make sure your new Cache is valid
if (newCache.valid)
{
//If you wanted to set your newly created cache to the active cache
Caching.currentCacheForWriting = newCache;
}
}
答案 0 :(得分:2)
您应该在Android中启用此权限READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions
。
您可以关注此博客以在运行时启用权限,也可以输入清单
https://blog.xamarin.com/requesting-runtime-permissions-in-android-marshmallow/
或检查
检查并确认是否尚未授予用户 READ_EXTERNAL_STORAGE 和 WRITE_EXTERNAL_STORAGE ,请使用以下代码;
var permissions = new string[] { Manifest.Permission.ReadExternalStorage, Manifest.Permission.WriteExternalStorage };
RequestPermissions(permissions, 77);