无法使用PCLStorage或Xamarin Forms Labs在Android文件系统中创建文件夹/文件

Joe*_*ean 8 c# android xamarin

我正在使用Xamarin平台开发Android应用程序,我试图在我的本地存储上创建一个文件夹,但我没有成功.

首先,我尝试通过Xamarin Forms Labs创建的FileManager类使用System.IO命名空间.我传递"/ storage/emulated/0 /`"路径的函数片段.

        public void CreateDirectory(string path)
        {
            this.isolatedStorageFile.CreateDirectory(path);
        }

        public Stream OpenFile(string path, FileMode mode, FileAccess access)
        {
            return (Stream)this.isolatedStorageFile.OpenFile(path, (System.IO.FileMode)mode, (System.IO.FileAccess)access);
        }
Run Code Online (Sandbox Code Playgroud)

这不起作用,因此我选择使用PCLStorage库进行跨平台文件操作.我试过这段代码.

IFolder rootFolder = FileSystem.Current.LocalStorage;
folder = await rootFolder.CreateFolderAsync("wakesocial",
                CreationCollisionOption.OpenIfExists);
Run Code Online (Sandbox Code Playgroud)

没工作.我导航到内部存储的根目录,我没有看到该文件夹​​.

所以错误似乎并没有发生,因为使用的库是Android特有的.我已经在清单中读取和写入外部存储.所以问题是.应用程序是否有权在存储设备的根级别创建文件或文件夹,或者是否必须在特定位置创建文件或文件夹,例如在Android/data/packagename中

Dan*_*ted 1

在 Android 上,PCL Storage 的 LocalStorage 文件夹对应于“我的文档”特殊文件夹

我不确定您尝试在哪个路径中创建文件夹,但如果您知道该路径并且想要使用 PCL 存储,您应该能够使用它来获取与现有文件夹相对应的FileSystem.Current.GetFolderFromPathAsyncPCL 存储。IFolder