harmony 鸿蒙@ohos.storageStatistics (Application Storage Statistics)

2022-08-09 浏览 (715)

@ohos.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.

Modules to Import

import storageStatistics from "@ohos.storageStatistics";

storageStatistics.getTotalSizeOfVolume

getTotalSizeOfVolume(volumeUuid: string): Promise<number>

Asynchronously obtains the total size of the specified volume. This API uses a promise to return the result.

Required permissions: ohos.permission.STORAGE_MANAGER

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
volumeUuidstringYesUUID of the volume.

Return value

TypeDescription
Promise<number>Promise used to return the total size of the volume.

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

Asynchronously obtains the total size of the specified volume. This API uses a callback to return the result.

Required permissions: ohos.permission.STORAGE_MANAGER

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
volumeUuidstringYesUUID of the volume.
callbackAsyncCallback<number>YesCallback invoked to return the total size of the volume.

Example

let uuid = "";
storageStatistics.getTotalSizeOfVolume(uuid, function(error, number){
    // Do something.
    console.info("getTotalSizeOfVolume successfully:"+ number);
});

storageStatistics.getFreeSizeOfVolume

getFreeSizeOfVolume(volumeUuid: string): Promise<number>

Asynchronously obtains the available space of the specified volume. This API uses a promise to return the result.

Required permissions: ohos.permission.STORAGE_MANAGER

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
volumeUuidstringYesUUID of the volume.

Return value

TypeDescription
Promise<number>Promise used to return the available space of the volume.

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

Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result.

Required permissions: ohos.permission.STORAGE_MANAGER

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
volumeUuidstringYesUUID of the volume.
callbackAsyncCallback<number>YesCallback invoked to return the available space of the volume.

Example

let uuid = "";
storageStatistics.getFreeSizeOfVolume(uuid, function(error, number){
    // Do something.
    console.info("getFreeSizeOfVolume successfully:"+ number);
});

storageStatistics.getBundleStats9+

getBundleStats(packageName: string): Promise<BundleStats>

Asynchronously obtains space information of an application. This API uses a promise to return the result.

Required permissions: ohos.permission.STORAGE_MANAGER

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
packageNamestringYesBundle name of the application.

Return value

TypeDescription
Promise<Bundlestats>Promise used to return the space information 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

Asynchronously obtains space information of an application. This API uses a callback to return the result.

Required permissions: ohos.permission.STORAGE_MANAGER

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
packageNamestringYesBundle name of the application.
callbackAsyncCallback<Bundlestats>YesCallback invoked to return the space information obtained.

Example

let packageName = "";
storageStatistics.getBundleStats(packageName, function(error, BundleStats){
    // Do something.
    console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
});

storageStatistics.getCurrentBundleStats9+

getCurrentBundleStats(): Promise<BundleStats>

Asynchronously obtains space information of the current third-party application. This API uses a promise to return the result.

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

Return value

TypeDescription
Promise<Bundlestats>Promise used to return the space information obtained.

Example

let bundleStats = storageStatistics.getCurrentBundleStats();
console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));

storageStatistics.getCurrentBundleStats9+

getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void

Asynchronously obtains space information of the current third-party application. This API uses a callback to return the result.

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<BundleStats>YesCallback invoked to return the space information obtained.

Example

storageStatistics.getCurrentBundleStats(function(error, bundleStats){
    // Do something.
    console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
});

BundleStats9+

Attributes

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

NameTypeReadableWritableDescription
appSizenumberYesNoSize of the application.
cacheSizenumberYesNoCache size of the application.
dataSizenumberYesNoTotal data size of the application.

storageStatistics.getTotalSize9+

getTotalSize(): Promise<number>

Obtains the total space of the built-in memory card. This API uses a promise to return the result.

Required permissions: ohos.permission.STORAGE_MANAGER

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

Return value

TypeDescription
Promise<number>Promise used to return the total space of the built-in memory card.

Example

let number = storageStatistics.getTotalSize();
console.info("getTotalSize successfully:"+ JSON.stringify(number));

storageStatistics.getTotalSize9+

getTotalSize(callback: AsyncCallback<number>): void

Obtains the total space of the built-in memory card. This API uses a callback to return the result.

Required permissions: ohos.permission.STORAGE_MANAGER

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<number>YesCallback invoked to return the total space of the built-in memory card.

Example

storageStatistics.getTotalSize(function(error, number){
    // Do something.
    console.info("getTotalSize successfully:"+ JSON.stringify(number));
});

storageStatistics.getFreeSize9+

getFreeSize(): Promise<number>

Obtains the available space of the built-in memory card. This API uses a promise to return the result.

Required permissions: ohos.permission.STORAGE_MANAGER

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

Return value

TypeDescription
Promise<number>Promise used to return the available space of the built-in memory card.

Example

let number = storageStatistics.getFreeSize();
console.info("getFreeSize successfully:"+ JSON.stringify(number));

storageStatistics.getFreeSize9+

getFreeSize(callback: AsyncCallback<number>): void

Obtains the available space of the built-in memory card. This API uses a callback to return the result.

Required permissions: ohos.permission.STORAGE_MANAGER

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<number>YesCallback invoked to return the available space of the built-in memory card.

Example

storageStatistics.getFreeSize(function(error, number){
    // Do something.
    console.info("getFreeSize successfully:"+ JSON.stringify(number));
});

storageStatistics.getSystemSize9+

getSystemSize(): Promise<number>

Asynchronously obtains the system space. This API uses a promise to return the result.

Required permissions: ohos.permission.STORAGE_MANAGER

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

Return value

TypeDescription
Promise<number>Promise used to return the system 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

Asynchronously obtains the system space. This API uses a callback to return the result.

Required permissions: ohos.permission.STORAGE_MANAGER

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<number>YesCallback used to return the system space obtained.

Example

storageStatistics.getSystemSize(function(error, number){
    // Do something.
    console.info("getSystemSize successfully:"+ number);
});

storageStatistics.getUserStorageStats9+

getUserStorageStats(userId?: number): Promise<StorageStats>

Asynchronously obtains the space occupied by each type of user data. This API uses a promise to return the result.

Required permissions: ohos.permission.STORAGE_MANAGER

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
userIdnumberNoUser ID.
Value:
-  Set this parameter to the ID of the user to be queried.
-  If no value is specified, information about the current user is queried.

Return value

TypeDescription
Promise<StorageStats>Promise used to return the information obtained.

Example

let userId = 1;
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

Asynchronously obtains the space occupied by each type of user data. This API uses a callback to return the result.

Required permissions: ohos.permission.STORAGE_MANAGER

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
userIdnumberNoUser ID.
Value:
-  Set this parameter to the ID of the user to be queried.
-  If no value is specified, information about the current user is queried.
callbackAsyncCallback<StorageStats>YesCallback invoked to return the information obtained.

Example

let userId = 1;
storageStatistics.getUserStorageStats(userId, function(error, StorageStats){
    // Do something.
    console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
});

StorageStats9+

Attributes

System capability: SystemCapability.FileManagement.StorageService.SpatialStatistics

This is a system API and cannot be called by third-party applications.

NameTypeReadableWritableDescription
totalnumberYesNoTotal space of the built-in memory card.
audionumberYesNoSpace occupied by audio data.
videonumberYesNoSpace occupied by video data.
imagenumberYesNoSpace occupied by image data.
filenumberYesNoSpace occupied by files.
appnumberYesNoSpace occupied by application data.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

harmony 鸿蒙@ohos.WorkSchedulerExtensionAbility (Work Scheduler Callbacks)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/097456275f3243b98a0957fc9a70a602