Xamarin Android file system paths

痞子三分冷 提交于 2020-04-08 10:19:06

问题


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.


回答1:


I think this is what you need:

Edit

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



来源:https://stackoverflow.com/questions/35891550/xamarin-android-file-system-paths

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!