Local files for libgdx

It’s been a while since i checked on this topic, and our own Nex provided a solution. I had a slight missunderstanding on how internal files work on Android, Nex thankfully corrected my stupidity 🙂

What are local files? On Android, your application has a private directory it can store files in. These are usually refered to as internal files. Since we use the “internal” name for the assets/ directory, we decided to call these type of files “local” instead. Other applications or the user do not have access to this directory (unless they are rooted, then all bets are off). The local files directory is usually stored on the internal storage as far as i understand, so you shouldn’t go crazy with storing GBs of data there.

Our new FileType#Local allows you to write to that directory. On the desktop it will resole to the working directory, usually the directory you started the jar from. On Android it resolves to the internal directory of the application.

The local storage is always available, which is not true for external storage. You can create directories, list directories and so on and so forth, just as with external or absolute files. Local files are read/write.

Thanks for the addition Nex!

10 thoughts on “Local files for libgdx

  1. Good addition, I was a little confused as to how this worked in LibGDX so wrote up my own solution, but I’ll revert to this now.

    Isn’t it a little confusing to have something else called “internal” when all of the Android documentation uses “internal” to mean your “local”?

  2. Wow, really great that you actually added it.
    Now back to my code and fix my ugly workaround <:

  3. I agree that it can be a tad confusing to use ‘local’ to refer to what normal Android development would refer to as ‘internal’ but since we already had an ‘internal’ type there wasn’t much I could do. Actually, while I was doing this I wanted to call the new type ‘private’ but I felt that this created a sort of false sense of security since on the desktop these files are anything but private.

  4. Cool! Thanks to all, you are awesome!
    But what if i’m put in the internal storage save-data files and update app from market? I think saved data will be removed with game?
    Sorry my eng.

  5. @Alex

    When you update the application, the files will not be deleted.
    However, if you uninstall the application, the files will be deleted.

  6. Thanks guys, we needed the true ‘local’ files really badly. I can simplify my code now and remove those ugly workarounds!

  7. What access permission(read only or read and write) are allowed for rooted user? What is the best file handle for saving about locked feature?

Leave a Reply

Your email address will not be published.