Xamarin Android文件系统路径 [英] Xamarin Android file system paths

查看:492
本文介绍了Xamarin Android文件系统路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Android文件系统上写入和读取文件.您可能会认为这很简单,但是我似乎无法为实际存在的文件夹/路径找到正确的枚举器.

我已经阅读了同一主题的几篇文章,但是没有一个文章能直接回答这个问题,那些似乎已经解决了问题的文章,却使用了对我来说不可行的方法. 一些建议似乎与System.IO有关,而其他建议似乎与Java等价.

我想做的事情很简单,就是在内部存储中的某个位置创建文件(而不是外部SD卡等),而该文件可以通过设备本身(通过文件浏览器应用程序或类似工具)访问. >

如果一切顺利(目前还不行),那么我也想稍后再阅读.

我不是在寻找写入或读取文件的代码-我正在寻找的东西可以给我正确的文件夹路径,

我尝试了许多不同的变体,其中一些是:

Environment.GetFolderPath(Environment.SpecialFolder.Personal);

返回路径:/data/data/my_app_full_name/files/

全局::: Android.OS.Environment.ExternalStorageDirectory.AbsolutePath.ToString();

返回路径:/storage/emulated/0/

任何人都可以就使用哪个枚举器给出明确的答案吗? -非常感谢.

PS.我正在通过USB从Xamarin Studio在实际设备(Android 5.0.2)上启动该应用程序.

编辑:至少对我来说,答案是在注释中找到的,供misho重播.

解决方案

我认为这是您需要的:

修改

public static string Directorypath
    {
        get
        {
            return System.IO.Path.Combine((string)Android.OS.Environment.ExternalStorageDirectory, "FolderPath");
        }
    }

I'm trying to write and read a file on the Android file system. A task you would think would be straight forward, but I just can't seem to find the right enumerator for a folder/path that actually exists.

I have read several posts on the same subject but none of them give a straight answer to this question and those that seem to have fixed their issues, has done so with paths that doesn't seem to work for me. Some suggestions seem to be related to System.IO while others seem to be of the Java equivalent.

What I'm trying to do is something as simple as to create a file somewhere in the internal storage (NOT external SD card or something) that is accessible from the device itself (via File Browser app or similar).

If that goes well (which it currently doesn't) then I would also like to read it later on.

I'm not looking for code to write or read files - I'm looking for something that can give me the correct path to a folder where I can do this.

I have tried many different variants, some of which are:

Environment.GetFolderPath (Environment.SpecialFolder.Personal);

returns the path: /data/data/my_app_full_name/files/

global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath.ToString();

returns the path: /storage/emulated/0/

Can anyone give a clear answer as to which enumerator to use for this? - would be much appreciated.

PS. I'm launching the app on an actual device (Android 5.0.2) from Xamarin Studio via USB.

EDIT: The answer, for me at least, is found under the comments for replay by misho.

解决方案

I think this is what you need:

Edit

public static string Directorypath
    {
        get
        {
            return System.IO.Path.Combine((string)Android.OS.Environment.ExternalStorageDirectory, "FolderPath");
        }
    }

这篇关于Xamarin Android文件系统路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆