ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / External file functions
  • Overview
  • The different storage types
  • Internal storage
  • External storage
  • WLanguage functions available for managing the different storage areas
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
The file system on the devices running Android is divided into two main storage areas:
  • an "internal" area.
  • an "external" or "shared" area.
On Android 11, apps can no longer access certain storage locations. For more details on accessible storage locations, see Android 11: Changes in the behavior of applications.
The different storage types

Internal storage

The internal storage area is found in the non-volatile and non-removable memory of the device (called permanent memory). This internal storage area mainly contains the system files of the OS.
The applications are installed in this storage area by default. Some applications can be installed on the external storage area with some restrictions.
The internal storage area is always available for an application even if the device is connected by USB to a computer for example.
An application can create, modify or delete files in its own directory only (found in the internal storage area). This directory is automatically created when installing the application. In most cases, it is named "/data/data/<Name of full application package>. For example: /data/data/fr.pcsoft.MyApplication. The files found in this directory cannot be accessed by the other applications.
When uninstalling the application, the files created in this directory and in its sub-directories are automatically deleted by the system.

External storage

The external storage area can be found:
  • in the permanent memory of the device,
  • and/or in the movable memory (SD Card storage card).
Some devices divide their permanent memory into two partitions, the first one dedicated to the internal storage and the other one to the external storage. Therefore, even the devices without location for a SDCard include two distinct storage areas.
Several external storage areas can be found on the same device: for example, the first one corresponds to the "external" partition of the permanent memory while the other one corresponds to the SDCard. In this case, we talk of primary external storage area, secondary external storage area, etc. The choice for assigning the primary storage area to such or such location depends on the manufacturer.
The external storage area may not be accessible for an application at a given time. This is the case for example when the application is connected to the computer in USB mass storage mode.
An application can access in read mode AND in write mode to all the files and directories found on the external storage area(s) of the device.
Each application can have its own directory in each one of the external storage areas of the device.
  • In most cases, the name of this directory has the following format : <root external storage>/Android/data/<Name of full application package>. For example: /mnt/sdcard/Android/data/fr.pcsoft.MyApplication.
  • This directory must contain the private application files that do not have to be shared with other applications (even though any application can access them).
  • This directory can contain sub-directories with preset system names for storing different types of files (music, film, documents, download, etc.). A proper use of these preset directories allows for a better support of these files by the system.
  • The files found in the application directory are not automatically scanned by the system (even though this can be explicitly asked). For example, the photos saved in this directory will not be listed in the photo albums of the device.
  • This directory as well as the data found in it will be automatically deleted when uninstalling the application.
Remark: From Android 4.4 (KitKat), on the external storage space corresponding to movable memory (SDCard), the applications can create, modify or delete files in their own directory only. The other files of the external storage space are accessible in read-only.
If an application owns public files that must be shared with other applications, we advise you to store them outside its own directory. In this case, the files will not be deleted when uninstalling the application.
The primary storage space of the device can contain directories with preset system names for storing different types of public files (music, film, documents, download, etc.). A proper use of these preset directories allows for a better support of the files by the system. In particular, these directories are regularly scanned by the system in order to be listed and proposed when selecting media for example.
Permissions :
  • The READ_EXTERNAL_STORAGE permission is required to access the files found in the external storage space in read mode. This permission is automatic on the devices running an Android version earlier than version 4.4.
  • The WRITE_EXTERNAL_STORAGE permission is required to access the files found in the external storage space in write mode (creation, modification, deletion). This permission implicitly grants the read rights.
From Android 4.4 (KitKat), these permissions are not longer required to access the files found in the application directory.
From Android 10, applications must access files located in their own directories only. Any attempt to access files outside of these directories (in read or write mode) may fail. It is recommended not to use ssePublicxxx constants (withSysDirExternalStorage, for example) to avoid errors.
Remark: Applications running on Android 10 and generated with WINDEV Mobile will run as usual (if you use patch 118661 or 250Update 4 of WINDEV Mobile).
When the application is used on a device that runs Android 11, new restrictions appear:
  • applications can no longer read or write files to the external storage outside of:
  • in public directories, an application can only access (in read or write mode) the files that it has created.
    Remark: if the application is uninstalled and then reinstalled, it will no longer have access to files created by the version previously installed in the public directories of the external storage.

For more details, see Android 11: Changes in the behavior of applications.
WLanguage functions available for managing the different storage areas
Several WLanguage functions can be used to manage and identify the different storage spaces:
fCacheDirReturns the path of directory that will be used to store the data in cache on the internal storage space of application.
fCurrentDirReturns the path of the directory that will be used to store the private files of the application in the internal storage area.
Example: /data/data/fr.pcsoft.MyApplication/files
fDataDirReturns the path of the directory that will be used to store the database files of the application in the internal storage area.
Example: /data/data/fr.pcsoft.MyApplication/database
fExeDirReturns the root path of the application directory in the internal storage area.
Example: /data/data/fr.pcsoft.MyApplication
SysCacheExternalStorageReturns the path of directory that will be used to store the data in cache on the external storage space of application.
SysDirExternalStorageReturns the path of the directory that will be used to store files in the external storage space of the Android device.
SysDirStorageCardReturns the path of the root directory of the primary external storage space.
Example: /mnt/sdcard
SysMemoryExternalStorageReturns the amount of available memory on the external storage area of the device.
SysNbExternalStorageReturns the number of external storage spaces found on an Android device.
SysRemovableExternalStorageUsed to find out whether the external storage space corresponds to the movable memory (SD Card).
SysSpaceReturns the free space or the total space of the primary external storage space.
SysStatusExternalStorageReturns the availability status of the external storage space of the device.
SysStatusStorageCardReturns the availability status of the primary external storage space: available/read only/unavailable.
Minimum version required
  • Version 21
Comments
Click [Add] to post a comment

Last update: 12/21/2022

Send a report | Local help