-
- All Known Implementing Classes:
AndroidStorageService
,DesktopStorageService
,IOSStorageService
public interface StorageService
The storage service provides access to the private and public storage locations for the application offered by the native platform.Example
File privateStorage = StorageService.create() .flatMap(StorageService::getPrivateStorage) .orElseThrow(() -> new FileNotFoundException("Could not access private storage."));
);}Android Configuration
The permissions
Note: these modifications are handled automatically by Client plugin if it is used.android.permission.READ_EXTERNAL_STORAGE
andandroid.permission.WRITE_EXTERNAL_STORAGE
are required if you want to access the external storage on the device for read and/or write operations respectively. Defining write permissions implicitly activate read permissions as well.<manifest ...> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> ... <activity android:name="com.gluonhq.impl.attach.android.PermissionRequestActivity" /> </manifest>
iOS Configuration: none
- Since:
- 3.0.0
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static java.util.Optional<StorageService>
create()
Returns an instance ofStorageService
.java.util.Optional<java.io.File>
getPrivateStorage()
Get a storage directory that is private to the environment that is calling this method.java.util.Optional<java.io.File>
getPublicStorage(java.lang.String subdirectory)
Get a public storage directory location.boolean
isExternalStorageReadable()
Checks if external storage is available for read access.boolean
isExternalStorageWritable()
Checks if external storage is available for read and write access.
-
-
-
Method Detail
-
create
static java.util.Optional<StorageService> create()
Returns an instance ofStorageService
.- Returns:
- An instance of
StorageService
.
-
getPrivateStorage
java.util.Optional<java.io.File> getPrivateStorage()
Get a storage directory that is private to the environment that is calling this method. In the case of iOS or Android, the returned directory is private to the enclosing application.- Returns:
- an optional with a private storage directory for an application
-
getPublicStorage
java.util.Optional<java.io.File> getPublicStorage(java.lang.String subdirectory)
Get a public storage directory location.Note that on Android the public location could be mapped to a removable memory device and may not always be available. Users of this method are advised to call
isExternalStorageWritable()
orisExternalStorageReadable()
to avoid surprises.Note also that on Android, permissions will need to be set to access external storage. See: https://developer.android.com/training/basics/data-storage/files.html.
- Parameters:
subdirectory
- under the root of public storage that is required. On Android the supplied subdirectory should not be null.- Returns:
- an Optional of a File representing the requested directory location. The location may not yet exist. It is the responsibility of the programmer to ensure that the location exists before using it.
-
isExternalStorageWritable
boolean isExternalStorageWritable()
Checks if external storage is available for read and write access.- Returns:
- true if the externalStorage is writable (implies readable), false otherwise
-
isExternalStorageReadable
boolean isExternalStorageReadable()
Checks if external storage is available for read access.- Returns:
- true if the externalStorage is at least readable, false otherwise
-
-