I want to store a JSON to the file system. Where should i store the files so that the user can't see/delete them and that the files won't be deleted after a phone reboot/restart?
ApplicationData The directory for application data specific to the user executing the program. On non-Windows operating systems, this path is the value of the environment variable XDG_CONFIG_HOME if it is set, otherwise the ".config" directory in the current user's home directory.
CommonApplicationData The directory for data shared by applications. On non-Windows operating systems, the "/usr/share" directory.
LocalApplicationData The directory for application data shared by users of the computer. On non-Windows operating systems, this path is the value of the environment variable XDG_DATA_HOME if it is set, otherwise the ".local/share" directory in the current user's home directory.
Personal The personal or home directory for the current user. On non-Windows operating systems, this is the user's home directory.
Source: System.Environment.SpecialFolder
I don't understand what Personal is for exactly, but on most sites on the web i found people using it. Should i use one of these or am i looking at the wrong things?
And for storing at the moment (May 2017) my only two options are SQLite and PCLStorage.
You can use any of the below folders for your requirements. If I understood your questions correctly you want only the app to be able to access (create/updated/delete) certain files which should be preserved on phone reboot or restart and the user shouldn't be able to access the files. You can use any of the below special folders:
Environment.SpecialFolder.ApplicationData
is $HOME/.config
, which maps to /data/data/@PACKAGE_NAME@/files/.config
.
Environment.SpecialFolder.LocalApplicationData
is $HOME/.local/share
, which maps to /data/data/@PACKAGE_NAME@/files/.local/share
.
Environment.SpecialFolder.Personal
is $HOME
, which maps to /data/data/@PACKAGE_NAME@/files
Looking at the description and mapping to the file system, for saving a JSON file I would probably pick Environment.SpecialFolder.ApplicationData
, but there seems to be nothing wrong in picking either of the three based on how they map in the file system.
Notice that all these paths are within the specific directory for your app package so no other apps will be able to access these files. And neither will you be able to access them from any file system (unless the phone is rooted).
If you want more information on any file path, you can iterate through them, like this:
static void PrintFolderPath(System.Environment.SpecialFolder folder)
{
Console.WriteLine ("{0}={1}", folder, System.Environment.GetFolderPath(folder));
}
More reading: https://forums.xamarin.com/discussion/3773/system-environment-specialfolder