gpt4 book ai didi

c# - 在内存中创建文件夹?

转载 作者:搜寻专家 更新时间:2023-11-01 09:25:37 26 4
gpt4 key购买 nike

我尝试在内部存储器 android 中创建一个文件夹,但是在我统一构建一个应用程序然后在 android 上运行一个应用程序之后,我得到了异常:

"unauthorizedaccessexception access to the path is denied"

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;
}
}

最佳答案

您应该在 Android 中启用此权限READ_EXTERNAL_STORAGE 和 WRITE_EXTERNAL_STORAGE 权限。您可以按照此博客在运行时启用权限,也可以在 list 中提供 https://blog.xamarin.com/requesting-runtime-permissions-in-android-marshmallow/

或勾选

检查,如果用户尚未授予 READ_EXTERNAL_STORAGEWRITE_EXTERNAL_STORAGE,请使用以下代码;

var permissions = new string[] { Manifest.Permission.ReadExternalStorage, Manifest.Permission.WriteExternalStorage };
RequestPermissions(permissions, 77);

参见 references references 2

关于c# - 在内存中创建文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50931861/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com