1

Inside a Codename One app, I need an area (for developers and testers) that shows:

  • how much space is occupied by the Storage + FileSystemStorage;
  • the available space (useful also to alert the user if there isn't enough space to record videos or to take photos);
  • the list of saved files inside Storage + FileSystemStorage;
  • an option to reset the app, clearing both Storage and FileSystemStorage.

In the Codename One API, I found Storage.getInstance().clearCache and Storage.getInstance().clearStorage(), but I didn't find their equivalent for FileSystemStorage.

I'd like some tips for all these requirements. Thanks.

Francesco Galgani
  • 6,137
  • 3
  • 20
  • 23

1 Answers1

2

Storage is managed and so it's access is cached. File System clearing would be the equivalent of formatting your hard drive... Not an API one would expect to have.

Since storage is flat the implementation of clear storage is pretty trivial:

    String[] l = listStorageEntries();
    int llen = l.length;
    for(int iter = 0 ; iter < llen ; iter++) {
        deleteStorageFile(l[iter]);
    }

FileSystemStorage uses hierarchies so this wouldn't be practical.

Available space is only available on FileSystemStorage via getRootAvailableSpace(). Notice that this API might be a bit flaky as the OS's don't always report storage in clear terms. There are a lot of nuances in the way mobile OS's are partitioned, usually Storage maps to the first root in terms of the space it takes up but we can't guarantee this will always be the case.

If the goal is simply testing both Android and iOS provide a tool to inspect the amount of total storage taken by the app within their respective app settings.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65