Interface StorageService

  • 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.


     File privateStorage = StorageService.create()
          .orElseThrow(() -> new FileNotFoundException("Could not access private storage."));

    Android Configuration

    The permissions android.permission.READ_EXTERNAL_STORAGE and android.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.

    Note: these modifications are handled automatically by GluonFX plugin if it is used.
     <manifest ...>
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <activity android:name="" />

    iOS Configuration: none

    • Method Detail

      • getPrivateStorage

        java.util.Optional<> 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.
        an optional with a private storage directory for an application
      • getPublicStorage

        java.util.Optional<> 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() or isExternalStorageReadable() to avoid surprises.

        Note also that on Android, permissions will need to be set to access external storage. See:

        subdirectory - under the root of public storage that is required. On Android the supplied subdirectory should not be null.
        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.
        true if the externalStorage is writable (implies readable), false otherwise
      • isExternalStorageReadable

        boolean isExternalStorageReadable()
        Checks if external storage is available for read access.
        true if the externalStorage is at least readable, false otherwise