diff --git a/zh-cn/application-dev/reference/apis/js-apis-storage-statistics.md b/zh-cn/application-dev/reference/apis/js-apis-storage-statistics.md index dde71634ef505143dab3fad9920c71c5925282f3..3934392f9ea9ecd2181221d819d24c8689bac3ac 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-storage-statistics.md +++ b/zh-cn/application-dev/reference/apis/js-apis-storage-statistics.md @@ -4,7 +4,6 @@ > > - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > - API 9当前为Canary版本,仅供试用,不保证接口可稳定调用。 -> - 本模块接口为系统接口,三方应用不支持调用。 该模块提供空间查询相关的常用功能:包括对内外卡的空间查询,对应用分类数据统计的查询,对应用数据的查询等。 @@ -20,8 +19,12 @@ getTotalSizeOfVolume(volumeUuid: string): Promise<number> 异步获取指定卷的总空间大小,以promise方式返回。 +**需要权限**:ohos.permission.STORAGE_MANAGER + **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics +**系统API**:该接口为系统接口,三方应用不支持调用 + - 参数 | 参数名 | 类型 | 必填 | 说明 | @@ -51,8 +54,12 @@ getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback<number>):v 异步获取指定卷的总空间大小,以callback方式返回。 +**需要权限**:ohos.permission.STORAGE_MANAGER + **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics +**系统API**:该接口为系统接口,三方应用不支持调用 + - 参数 | 参数名 | 类型 | 必填 | 说明 | @@ -78,8 +85,12 @@ getFreeSizeOfVolume(volumeUuid: string): Promise<number> 异步获取指定卷的可用空间大小,以promise方式返回。 +**需要权限**:ohos.permission.STORAGE_MANAGER + **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics +**系统API**:该接口为系统接口,三方应用不支持调用 + - 参数 | 参数名 | 类型 | 必填 | 说明 | @@ -110,8 +121,12 @@ getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback<number>):vo 异步获取指定卷的可用空间大小,以callback方式返回。 +**需要权限**:ohos.permission.STORAGE_MANAGER + **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics +**系统API**:该接口为系统接口,三方应用不支持调用 + - 参数 | 参数名 | 类型 | 必填 | 说明 | @@ -135,8 +150,12 @@ getBundleStats(packageName: string): Promise<BundleStats> 异步获取应用存储数据,以promise方式返回。 +**需要权限**:ohos.permission.STORAGE_MANAGER + **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics +**系统API**:该接口为系统接口,三方应用不支持调用 + - 参数 | 参数名 | 类型 | 必填 | 说明 | @@ -166,8 +185,12 @@ getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>) 异步获取应用存储数据,以callback方式返回。 +**需要权限**:ohos.permission.STORAGE_MANAGER + **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics +**系统API**:该接口为系统接口,三方应用不支持调用 + - 参数 | 参数名 | 类型 | 必填 | 说明 | @@ -185,14 +208,310 @@ getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>) }); ``` + + +## storagestatistics.getCurrentBundleStats9+ + +getCurrentBundleStats(): Promise + +第三方应用异步获取占用空间,以promise方式返回。 + +**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics + +- 返回值 + + | 类型 | 说明 | + | ------------------------------------------ | -------------------------- | + | Promise<[Bundlestats](#bundlestats)> | 返回指定卷上的应用存储状态 | + +- 示例 + + ```js + let bundleStats = await storageStatistics.getCurrentBundleStats(); + console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats)); + ``` + +## storagestatistics.getCurrentBundleStats9+ + +getCurrentBundleStats(callback: AsyncCallback): void + +第三方应用异步获取占用空间,以callback方式返回。 + +**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | --------------------------------------------------------- | ---- | ------------------------------------ | + | callback | callback:AsyncCallback<[BundleStats](#bundlestats)> | 是 | 获取指定卷上的应用存储状态之后的回调 | + +- 示例 + + ```js + storagestatistics.getCurrentBundleStats(function(error, bundleStats){ + // do something + console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats)); + }); + ``` + + + ## BundleStats9+ **系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics。 -### 属性 +- 属性 + +| 名称 | 类型 | 说明 | +| --------- | ------ | -------------- | +| appSize | number | app数据大小 | +| cacheSize | number | 缓存数据大小 | +| dataSize | number | 应用总数据大小 | + + + + +## storagestatistics.getTotalSize9+ + +getTotalSize(): Promise + +获取内卡的总空间大小,以promise方式返回。 + +**需要权限**:ohos.permission.STORAGE_MANAGER + +**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics + +**系统API**:该接口为系统接口,三方应用不支持调用 + +- 返回值 + + | 类型 | 说明 | + | --------------------- | ------------------ | + | Promise<number> | 返回内卡的总空间大小 | + +- 示例 + + ```js + let number = await storageStatistics.getTotalSize(); + console.info("getTotalSize successfully:"+ JSON.stringify(number)); + ``` + +## storagestatistics.getTotalSize9+ + +getTotalSize(callback: AsyncCallback): void + +获取内卡的总空间大小,以callback方式返回。 + +**需要权限**:ohos.permission.STORAGE_MANAGER + +**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics + +**系统API**:该接口为系统接口,三方应用不支持调用 + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------------------------------------ | ---- | ------------------------ | + | callback | callback:AsyncCallback<number> | 是 | 获取内卡的总空间大小之后的回调 | + +- 示例 + + ```js + storagestatistics.getTotalSize(function(error, number){ + // do something + console.info("getTotalSize successfully:"+ JSON.stringify(number)); + }); + ``` + + +## storagestatistics.getFreeSize9+ + +getFreeSize(): Promise + +获取内卡的可用空间大小,以promise方式返回。 + +**需要权限**:ohos.permission.STORAGE_MANAGER + +**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics + +**系统API**:该接口为系统接口,三方应用不支持调用 + +- 返回值 + + | 类型 | 说明 | + | --------------------- | ------------------ | + | Promise<number> | 返回内卡的可用空间大小 | + +- 示例 + + ```js + let number = await storageStatistics.getFreeSize(); + console.info("getFreeSize successfully:"+ JSON.stringify(number)); + ``` + + +## storagestatistics.getFreeSize9+ + +getFreeSize(callback: AsyncCallback): void + +获取内卡的可用空间大小,以callback方式返回。 + +**需要权限**:ohos.permission.STORAGE_MANAGER + +**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics + +**系统API**:该接口为系统接口,三方应用不支持调用 + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------------------------------------ | ---- | ------------------------- | + | callback | callback:AsyncCallback<number> | 是 | 获取内卡的可用空间大小之后的回调 | + +- 示例 + + ```js + storagestatistics.getFreeSize(function(error, number){ + // do something + console.info("getFreeSize successfully:"+ JSON.stringify(number)); + }); + ``` + + + +## storagestatistics.getSystemSize9+ + +getSystemSize(): Promise<number> + +异步获取系统空间大小,以promise方式返回。 + +**需要权限**:ohos.permission.STORAGE_MANAGER + +**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics + +**系统API**:该接口为系统接口,三方应用不支持调用 + +- 返回值 + + | 类型 | 说明 | + | --------------------- | ---------------- | + | Promise<number> | 返回系统空间大小 | + +- 示例 + + ```js + 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 + +异步获取系统空间大小,以callback方式返回。 + +**需要权限**:ohos.permission.STORAGE_MANAGER + +**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics + +**系统API**:该接口为系统接口,三方应用不支持调用 + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | ---------- | ------------------------------------ | ---- | -------------------------- | + | callback | callback:AsyncCallback<number> | 是 | 获取系统空间大小之后的回调 | + +- 示例 + + ```js + storagestatistics.getSystemSize(function(error, number){ + // do something + console.info("getSystemSize successfully:"+ number); + }); + ``` + + + +## storagestatistics.getUserStorageStats9+ + +getUserStorageStats(userId?: string): Promise<StorageStats> + +异步获取用户各类别数据大小,以promise方式返回。 + +**需要权限**:ohos.permission.STORAGE_MANAGER + +**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics + +**系统API**:该接口为系统接口,三方应用不支持调用 + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | ---------- | ------ | ---- | ---- | + | userId | string | 否 | 用户id
确认当前用户:
- 有值:表示指定用户。
- 无值:表示当前用户。| + +- 返回值 + + | 类型 | 说明 | + | --------------------- | ---------------- | + | Promise<[StorageStats](#StorageStats)> | 返回各类别数据大小 | + +- 示例 + + ```js + let userId = ""; + 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?: string, callback:AsyncCallback<StorageStats>):void + +异步获取用户各类别数据大小,以callback方式返回。 + +**需要权限**:ohos.permission.STORAGE_MANAGER + +**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics + +**系统API**:该接口为系统接口,三方应用不支持调用 + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | ---------- | ------------------------------------ | ---- | -------------------------- | + | userId | string | 否 | 用户id
确认当前用户:
- 有值:表示指定用户。
- 无值:表示当前用户。 | + | callback | callback:AsyncCallback<[StorageStats](#StorageStats)> | 是 | 返回各类别数据大小之后的回调 | + +- 示例 + + ```js + storagestatistics.getUserStorageStats(userId, function(error, StorageStats){ + // do something + console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats)); + }); + ``` + + + +## StorageStats9+ + +**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics。 + +- 属性 | 名称 | 类型 | 说明 | | --------- | ------ | -------------- | -| appSize9+ | number | app数据大小 | -| cacheSize9+ | number | 缓存数据大小 | -| dataSize9+ | number | 应用总数据大小 | \ No newline at end of file +| total | number | 内卡总空间大小 | +| audio | number | 音频数据大小 | +| video | number | 视频数据大小 | +| image | number | 图像数据大小 | +| file | number | 文件数据大小 | +| app | number | 应用数据大小 |