3

I am working with @capacitor/filesystem package and struggle with picking directories for specific purposes. The package has the following enum defined:

export declare enum Directory {
    /**
     * The Documents directory
     * On iOS it's the app's documents directory.
     * Use this directory to store user-generated content.
     * On Android it's the Public Documents folder, so it's accessible from other apps.
     * It's not accesible on Android 10 unless the app enables legacy External Storage
     * by adding `android:requestLegacyExternalStorage="true"` in the `application` tag
     * in the `AndroidManifest.xml`.
     * It's not accesible on Android 11 or newer.
     *
     * @since 1.0.0
     */
    Documents = "DOCUMENTS",
    /**
     * The Data directory
     * On iOS it will use the Documents directory.
     * On Android it's the directory holding application files.
     * Files will be deleted when the application is uninstalled.
     *
     * @since 1.0.0
     */
    Data = "DATA",
    /**
     * The Library directory
     * On iOS it will use the Library directory.
     * On Android it's the directory holding application files.
     * Files will be deleted when the application is uninstalled.
     *
     * @since 1.1.0
     */
    Library = "LIBRARY",
    /**
     * The Cache directory
     * Can be deleted in cases of low memory, so use this directory to write app-specific files
     * that your app can re-create easily.
     *
     * @since 1.0.0
     */
    Cache = "CACHE",
    /**
     * The external directory
     * On iOS it will use the Documents directory
     * On Android it's the directory on the primary shared/external
     * storage device where the application can place persistent files it owns.
     * These files are internal to the applications, and not typically visible
     * to the user as media.
     * Files will be deleted when the application is uninstalled.
     *
     * @since 1.0.0
     */
    External = "EXTERNAL",
    /**
     * The external storage directory
     * On iOS it will use the Documents directory
     * On Android it's the primary shared/external storage directory.
     * It's not accesible on Android 10 unless the app enables legacy External Storage
     * by adding `android:requestLegacyExternalStorage="true"` in the `application` tag
     * in the `AndroidManifest.xml`.
     * It's not accesible on Android 11 or newer.
     *
     * @since 1.0.0
     */
    ExternalStorage = "EXTERNAL_STORAGE"
}

From what it says, Android 11 or newer can only utilize Data, Library, Cache, and External folders.


From my understanding, I can use and I need to store the following types of content:

  • Library/Data/External: System files (database files)
  • Data/External: User-uploaded data (images, videos, files, uploaded to the application)
  • ?: Downloads from my application (backup export)

So, I have the following questions:

  • Which directories should I use to store these types of data and why?
  • Also, what is meant by shared/external? SD card?
  • What's the difference between External and ExternalStorage? Both were introduced at the same time (since 1.0.0). Do they end up pointing to different locations?

For external downloads from my application (backup export) I tried to use Documents directory (Download folder in it, specified via a separate path parameter), and it seems to be working for me, even though my phone is Android 12 (Funtouch OS_10.5). I am not sure if it will also be working for other users on other systems.

I also tried checking out Android documentation on that topic, but it seems to not be bound to these enum values.

0 Answers0