@ohos.file.storageStatistics (Application Storage Statistics)
The storageStatistics module provides APIs for obtaining storage space information, including the space of built-in and plug-in memory cards, space occupied by different types of data, and space of application data.
NOTE
- The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
- The APIs of this module support processing of error codes. For details, see File Management Error Codes.
Modules to Import
import storageStatistics from "@ohos.file.storageStatistics";
storageStatistics.getTotalSizeOfVolume
getTotalSizeOfVolume(volumeUuid: string): Promise<number>
Obtains the total size (in bytes) of the specified volume in an external storage device. This API uses a promise to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
volumeUuid | string | Yes | UUID of the volume. |
Return value
Type | Description |
---|---|
Promise<number> | Promise used to return the total volume size obtained. |
Example
let uuid = "";
storageStatistics.getTotalSizeOfVolume(uuid).then(function(number){
console.info("getTotalSizeOfVolume successfully:"+ number);
}).catch(function(err){
console.info("getTotalSizeOfVolume failed with error:"+ err);
});
storageStatistics.getTotalSizeOfVolume
getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void
Obtains the total size (in bytes) of the specified volume in an external storage device. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
volumeUuid | string | Yes | UUID of the volume. |
callback | AsyncCallback<number> | Yes | Callback invoked to return the total volume size obtained. |
Example
let uuid = "";
storageStatistics.getTotalSizeOfVolume(uuid, function(error, number){
// Do something.
console.info("getTotalSizeOfVolume successfully:"+ number);
});
storageStatistics.getFreeSizeOfVolume
getFreeSizeOfVolume(volumeUuid: string): Promise<number>
Obtains the available space (in bytes) of the specified volume in an external storage device. This API uses a promise to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
volumeUuid | string | Yes | UUID of the volume. |
Return value
Type | Description |
---|---|
Promise<number> | Promise used to return the available volume space obtained. |
Example
let uuid = "";
storageStatistics.getFreeSizeOfVolume(uuid).then(function(number){
console.info("getFreeSizeOfVolume successfully:"+ number);
}).catch(function(err){
console.info("getFreeSizeOfVolume failed with error:"+ err);
});
storageStatistics.getFreeSizeOfVolume
getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void
Obtains the available space (in bytes) of the specified volume in an external storage device. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
volumeUuid | string | Yes | UUID of the volume. |
callback | AsyncCallback<number> | Yes | Callback invoked to return the available volume space obtained. |
Example
let uuid = "";
storageStatistics.getFreeSizeOfVolume(uuid, function(error, number){
// Do something.
console.info("getFreeSizeOfVolume successfully:"+ number);
});
storageStatistics.getBundleStats9+
getBundleStats(packageName: string): Promise<BundleStats>
Obtains the space (in bytes) of an application. This API uses a promise to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
packageName | string | Yes | Bundle name of the application. |
Return value
Type | Description |
---|---|
Promise<Bundlestats> | Promise used to return the application space obtained. |
Example
let packageName = "";
storageStatistics.getBundleStats(packageName).then(function(BundleStats){
console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
}).catch(function(err){
console.info("getBundleStats failed with error:"+ err);
});
storageStatistics.getBundleStats9+
getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>): void
Obtains the space (in bytes) of an application. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
packageName | string | Yes | Bundle name of the application. |
callback | AsyncCallback<Bundlestats> | Yes | Callback invoked to return the application space obtained. |
Example
let packageName = "";
storageStatistics.getBundleStats(packageName, function(error, BundleStats){
// Do something.
console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
});
storageStatistics.getCurrentBundleStats9+
getCurrentBundleStats(): Promise<BundleStats>
Obtains the space (in bytes) of this third-party application. This API uses a promise to return the result.
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
Return value
Type | Description |
---|---|
Promise<Bundlestats> | Promise used to return the application space obtained. |
Example
let bundleStats = storageStatistics.getCurrentBundleStats();
console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
storageStatistics.getCurrentBundleStats9+
getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void
Obtains the space (in bytes) of this third-party application. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<BundleStats> | Yes | Callback invoked to return the application space obtained. |
Example
storageStatistics.getCurrentBundleStats(function(error, bundleStats){
// Do something.
console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
});
BundleStats9+
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
Name | Type | Readable | Writable | Description |
---|---|---|---|---|
appSize | number | Yes | No | Size of the application, in bytes. |
cacheSize | number | Yes | No | Cache size of the application, in bytes. |
dataSize | number | Yes | No | Total data size of the application, in bytes. |
storageStatistics.getTotalSize9+
getTotalSize(): Promise<number>
Obtains the total size (in bytes) of the built-in storage. This API uses a promise to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Return value
Type | Description |
---|---|
Promise<number> | Promise used to return the built-in storage size obtained. |
Example
let number = storageStatistics.getTotalSize();
console.info("getTotalSize successfully:"+ JSON.stringify(number));
storageStatistics.getTotalSize9+
getTotalSize(callback: AsyncCallback<number>): void
Obtains the total size (in bytes) of the built-in storage. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<number> | Yes | Callback invoked to return the built-in storage size obtained. |
Example
storageStatistics.getTotalSize(function(error, number){
// Do something.
console.info("getTotalSize successfully:"+ JSON.stringify(number));
});
storageStatistics.getFreeSize9+
getFreeSize(): Promise<number>
Obtains the available space (in bytes) of the built-in storage. This API uses a promise to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Return value
Type | Description |
---|---|
Promise<number> | Promise used to return the available space of the built-in storage obtained. |
Example
let number = storageStatistics.getFreeSize();
console.info("getFreeSize successfully:"+ JSON.stringify(number));
storageStatistics.getFreeSize9+
getFreeSize(callback: AsyncCallback<number>): void
Obtains the available space (in bytes) of the built-in storage. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<number> | Yes | Callback invoked to return the available space of the built-in storage obtained. |
Example
storageStatistics.getFreeSize(function(error, number){
// Do something.
console.info("getFreeSize successfully:"+ JSON.stringify(number));
});
storageStatistics.getSystemSize9+
getSystemSize(): Promise<number>
Obtains the system data space, in bytes. This API uses a promise to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Return value
Type | Description |
---|---|
Promise<number> | Promise used to return the system data space obtained. |
Example
storageStatistics.getSystemSize().then(function(number){
console.info("getSystemSize successfully:"+ number);
}).catch(function(err){
console.info("getSystemSize failed with error:"+ err);
});
storageStatistics.getSystemSize9+
getSystemSize(callback: AsyncCallback<number>): void
Obtains the system data space, in bytes. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<number> | Yes | Callback invoked to return the system data space obtained. |
Example
storageStatistics.getSystemSize(function(error, number){
// Do something.
console.info("getSystemSize successfully:"+ number);
});
storageStatistics.getUserStorageStats9+
getUserStorageStats(): Promise<StorageStats>
Obtains the storage statistics (in bytes) of this user. This API uses a promise to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Return value
Type | Description |
---|---|
Promise<StorageStats> | Promise used to return the information obtained. |
Example
storageStatistics.getUserStorageStats().then(function(StorageStats){
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
}).catch(function(err){
console.info("getUserStorageStats failed with error:"+ err);
});
storageStatistics.getUserStorageStats9+
getUserStorageStats(callback: AsyncCallback<StorageStats>): void
Obtains the storage statistics (in bytes) of this user. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<StorageStats> | Yes | Callback invoked to return the information obtained. |
Example
storageStatistics.getUserStorageStats(function(error, StorageStats){
// Do something.
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
});
getUserStorageStats(userId: number): Promise<StorageStats>
Obtains the storage statistics (in bytes) of the specified user. This API uses a promise to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
userId | number | Yes | User ID. |
Return value
Type | Description |
---|---|
Promise<StorageStats> | Promise used to return the information obtained. |
Example
let userId = 100;
storageStatistics.getUserStorageStats(userId).then(function(StorageStats){
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
}).catch(function(err){
console.info("getUserStorageStats failed with error:"+ err);
});
storageStatistics.getUserStorageStats9+
getUserStorageStats(userId: number, callback: AsyncCallback<StorageStats>): void
Obtains the storage statistics (in bytes) of the specified user. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
userId | number | Yes | User ID. |
callback | AsyncCallback<StorageStats> | Yes | Callback invoked to return the information obtained. |
Example
let userId = 100;
storageStatistics.getUserStorageStats(userId, function(error, StorageStats){
// Do something.
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
});
StorageStats9+
System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics
System API: This is a system API.
Name | Type | Readable | Writable | Description |
---|---|---|---|---|
total | number | Yes | No | Total size of the built-in storage, in bytes. |
audio | number | Yes | No | Space occupied by audio data, in bytes. |
video | number | Yes | No | Space occupied by video data, in bytes. |
image | number | Yes | No | Space occupied by image data, in bytes. |
file | number | Yes | No | Space occupied by files, in bytes. |
app | number | Yes | No | Space occupied by application data, in bytes. |