Data Storages
You can access storage information and manage directories within certain parts of the file system, represented as virtual root locations. These virtual roots form a collection of locations that function as a single virtual device file system.
The main features of the Tizen.System.Storage
class includes the following:
-
Storage management
You can manage different storage locations on the device.
You can retrieve additional information about the storage locations, including which storage is supported on the device, using the Tizen.System.StorageManager class. You can also monitor storage state changes.
-
Storage space management
You can get the available and total size of the storage.
Prerequisites
To use the methods and properties of the Tizen.System.Storage and Tizen.System.StorageManager classes, include the Tizen.System namespace in your application:
C#
Copy
using Tizen.System;
Retrieve storage information
To retrieve storage information, follow the steps below:
-
Retrieve all storages on a device by using the
Storages
property of the Tizen.System.StorageManager class, which returns a list of all device storages as instances of the Tizen.System.Storage class:C#Copyvar storages = StorageManager.Storages; var internalStorage = storages.Where(s => s.StorageType == StorageArea.Internal).FirstOrDefault();
-
To get information about each storage instance, follow these steps:
-
Get the ID of a specific storage by using the
Id
property:C#Copyvar result = internalStorage.Id;
-
Get the root directory of a specific storage by using the
RootDirectory
property:C#Copyvar result = internalStorage.RootDirectory;
-
Get the directory path for a storage of a specific type.
The
GetAbsolutePath()
method of theTizen.System.Storage
class retrieves the absolute path to a storage of a particular type, which is defined by the values of the Tizen.System.DirectoryType enumeration.To get the directories of all storage types:
C#Copyforeach (DirectoryType directoryType in Enum.GetValues(typeof(DirectoryType))) { var result = internalStorage.GetAbsolutePath(directoryType); }
-
Get the storage type of a specific storage by using the
StorageType
property, which takes values from the Tizen.System.StorageArea enumeration:C#Copyvar result = internalStorage.StorageType;
-
Get the mount state of a specific storage by using the
State
property, which takes values from the Tizen.System.StorageState enumeration:C#Copyvar result = internalStorage.State;
-
Monitor storage state changes
To monitor storage state changes, follow the steps below:
-
Define an event handler, which is called when the storage state changes:
C#CopyEventHandler storageEventHandler = (s, e) => { var storage = s as Storage; if (storage == null) { return; } if (storage.State == StorageState.Unmountable) { unmountableStateAchieved = true; } };
The event handler checks whether storage can be mounted or is corrupted and unmountable.
-
Register the event handler for the
StorageStateChanged
event of the Tizen.System.Storage class:C#Copyforeach (var storage in StorageManager.Storages) { storage.StorageStateChanged += storageEventHandler; }
-
When no longer needed, deregister the event handler:
C#Copyforeach (var storage in StorageManager.Storages) { storage.StorageStateChanged -= storageEventHandler; }
Retrieve storage space information
To get the available and total size of the storage, use the TotalSpace
and AvailableSpace
properties in the Tizen.System.Storage class. For internal storage, they return the storage size, excluding the minimum memory size to launch the low memory pop-up in a low memory situation. Consequently, the available size must be less than the original available size, and you must use these properties to get the memory size.
To retrieve storage space information, follow the steps below:
-
Get the total space of the storage by using the
TotalSpace
property, which returns the total space of the given storage in bytes:C#Copyvar storages = StorageManager.Storages; var internalStorage = storages.Where(s => s.StorageType == StorageArea.Internal).FirstOrDefault(); var result = internalStorage.TotalSpace;
-
Get the available space of the storage by using the
AvailableSpace
property, which returns the available space of the given storage in bytes:C#Copyvar storages = StorageManager.Storages; var internalStorage = storages.Where(s => s.StorageType == StorageArea.Internal).FirstOrDefault(); var result = internalStorage.AvailableSpace;
Virtual roots
The following table lists the supported virtual roots.
Table: File system virtual roots
Virtual root | Description |
---|---|
Images |
Location for storing images. |
Sounds |
Location for storing sound files. |
Videos |
Location for storing video files. |
Camera |
Location for storing photos. |
Downloads |
Location for storing downloaded items. |
Music |
Location for storing audio files. |
Documents |
Location for storing documents. |
Others |
Location for storing other files. |
Ringtones |
Location for ringtones (read-only location). |
Related information
- Dependencies
- Tizen 4.0 and Higher