java.lang.Object | |
↳ | com.neomades.io.file.FileStorage |
Provides accesses to the various defined area of the filesystem.
It is necessary to understand how the filesystem is organized before interacting with it. There are several places where data can be saved or read for an application:
getCacheDir()
): data the user does not
need to access but that improve application performance if stored. This area
may be clean by the filesystem if it requires space.getApplicationDir()
): area in the
application for user content (not limited in space). Data will only be
available in the application.getExternalApplicationDir()
), only for Android: it can be
the SDCard or a dedicated storage area on the device but it is a space
reserved to the application. it cannot be accessed outside the application.
For cross-platform compatibility, prefer using
getApplicationDir()
.getApplicationDir()
.
The EXTERNAL_STORAGE
permission is needed to use the
#getExternalDir() method on the Android platform.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static File |
getApplicationDir()
Returns the absolute path to a directory to store user-generated content
inside the application reserved area.
| ||||||||||
static File |
getCacheDir()
Returns the absolute path to the application specific cache directory on the
filesystem.
| ||||||||||
static File |
getExternalApplicationDir()
Returns the primary shared/external storage directory if possible.
| ||||||||||
static boolean |
isExternalDirAvailable()
Returns
true if the external storage can be accessed in the
filesystem. | ||||||||||
static void |
requestExternalDir(ExternalDirCallback externalDirCallback)
Requests for the primary shared/external storage directory.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Returns the absolute path to a directory to store user-generated content inside the application reserved area.
This folder should be use to store any contents that must be available for the user (to create, import, delete or edit). For example, for a drawing image it can be any graphic files the user creates, for an audio player it can be downloaded music...
In all platforms this folder is back up with the application.
No permissions are required to work with the application directory.
null
)Returns the absolute path to the application specific cache directory on the filesystem.
The system may automatically delete files in this directory as disk space is needed elsewhere on the device.
This folder must be used to save some data that are not mandatory for the application but that can improve performance. For example, it can be database cache files and transient, downloadable content...
Try to keep the cache to a reasonable space (around 1MB) since the filesystems will prefer to delete big cache first if it requires space.
No permissions are required to work with the cache directory.
null
)
Returns the primary shared/external storage directory if possible. Otherwise,
returns the application reserved area (Application dir).
These files are considered as internal to the applications even if they are
in the external storage (it is the main difference with
#getExternalDir(). Typically, data will not be visible to the user as
media. This directory may not currently be accessible if it has been mounted
by the user on their computer, has been removed from the device, or some
other problem has happened.
By external storage, it can be the SDCard or a dedicated storage area on the device. It depends of the implementation of the functionality on the device.
No permissions are required to work with the cache directory.
Available only on Android In other platforms, this method returns the
internal application dir (the same path as getApplicationDir()
).
getApplicationDir()
Returns true
if the external storage can be accessed in the
filesystem. It is true only on Android.
true
if the directory is available
Requests for the primary shared/external storage directory. This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened.
By external storage, it can be the SDCard or a dedicated storage area on the device. It depends of the implementation of the functionality on the device.
Contrary to getApplicationDir()
this does not write in a protected
area within the application. The data will be accessible outside the
application. Prefer using getApplicationDir()
except if you want the
data to be accessible outside the application.
The EXTERNAL_STORAGE
permission is needed to use this method.
To write data on the external storage but on a place reserved to the
application, use getExternalApplicationDir()
.
Available only on Android
externalDirCallback | a callback to retrieve the directory and information around it (availability on the platform, user permissions...) |
---|