Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Where to save private user data?

Discussion in 'Android' started by greymag, Apr 4, 2019.

  1. greymag

    greymag

    Joined:
    Oct 2, 2017
    Posts:
    6
    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:
    https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

    In Android documentation https://developer.android.com/training/data-storage/files

    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?
     
  2. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
    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.
     
  3. greymag

    greymag

    Joined:
    Oct 2, 2017
    Posts:
    6
    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).
     
    mouizeroo and rjuhasz like this.