Where to save private user data?

Hello.

I want to save user data in private folder on Android. I need it because user save data have information about user balance, lives, etc, which must not be available for user to edit in easy way.

All the tutorials that I read offer the same thing: save data in Application.persistentDataPath. But this path is refers to public folder:

In Android documentation Omówienie danych i miejsca na pliki  |  Android Developers

External storage:

  • It’s not always available, because the user can mount the external storage as USB storage and in some cases remove it from the device.
  • It’s world-readable, so files saved here may be read outside of your control.

So, obviously it’s not a good choice for saving valuable private user data.

What I’m need - it’s internal storage.

Internal storage:

  • It’s always available.
  • Files saved here are accessible by only your app.

My questions is:

  • Do Unity have property for get path which resolved using android.content.Context.getFilesDir()?
  • If not, which path I should use for my purpose?

AFAIK there isn’t any Unity path that leads to getFilesDir(), you have to use/create plugin for that

These are the paths available in Application
dataPath
persistentDataPath
streamingAssetsPath
temporaryCachePath

And if you want to disable easy user edit of your save files, then just encrypting them is easier than messing with file paths.

Thanks for answer. I did read the documentation =) Also I’m familiar with plugins development. But I’m confused that Unity does not have this simple feature. Maybe I missed something.

Encryption may resolve some of this problems, but it’s not resolve that save can be on SD card (it’s bad - user can easy loss his progress), and that other program can view or remove file (for example same cleaning application).

2 Likes