Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Android file system paths

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.

like image 854
Aidal Avatar asked Mar 09 '16 12:03

Aidal


1 Answers

I think this is what you need:

Edit

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

enter image description here

like image 122
arsena Avatar answered Sep 21 '22 18:09

arsena