Codename One Storage and FileSystemStorage space occupied, available space, list of files and clearing

雨燕双飞 提交于 2019-12-11 05:35:45

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/53992318/codename-one-storage-and-filesystemstorage-space-occupied-available-space-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!