1e41f4b71Sopenharmony_ci# @ohos.file.storageStatistics (应用空间统计)(系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci该模块提供空间查询相关的常用功能:包括对内外卡的空间查询,对应用分类数据统计的查询,对应用数据的查询等。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.file.storageStatistics (应用空间统计)](js-apis-file-storage-statistics.md)。 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## 导入模块 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci```ts 13e41f4b71Sopenharmony_ciimport storageStatistics from "@ohos.file.storageStatistics"; 14e41f4b71Sopenharmony_ci``` 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## storageStatistics.getTotalSizeOfVolume 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_cigetTotalSizeOfVolume(volumeUuid: string): Promise<number> 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci异步获取外置存储设备中指定卷设备的总空间大小(单位为Byte),以Promise方式返回。 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci**参数:** 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 31e41f4b71Sopenharmony_ci | ---------- | ------ | ---- | ---- | 32e41f4b71Sopenharmony_ci | volumeUuid | string | 是 | 卷设备uuid | 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci**返回值:** 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci | 类型 | 说明 | 37e41f4b71Sopenharmony_ci | --------------------- | ---------------- | 38e41f4b71Sopenharmony_ci | Promise<number> | Promise对象,返回指定卷设备的总空间大小(单位为Byte) | 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci**错误码:** 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 45e41f4b71Sopenharmony_ci| -------- | -------- | 46e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 47e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 48e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 49e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 50e41f4b71Sopenharmony_ci| 13600008 | No such object. | 51e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci**示例:** 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci ```ts 56e41f4b71Sopenharmony_ci import volumemanager from "@ohos.file.volumeManager"; 57e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 58e41f4b71Sopenharmony_ci volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => { 59e41f4b71Sopenharmony_ci let uuid: string = volumes[0].uuid; 60e41f4b71Sopenharmony_ci storageStatistics.getTotalSizeOfVolume(uuid).then((number: number) => { 61e41f4b71Sopenharmony_ci console.info("getTotalSizeOfVolume successfully:" + number); 62e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 63e41f4b71Sopenharmony_ci console.error("getTotalSizeOfVolume failed with error:" + JSON.stringify(err)); 64e41f4b71Sopenharmony_ci }); 65e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 66e41f4b71Sopenharmony_ci console.error("getAllVolumes failed with error:" + JSON.stringify(err)); 67e41f4b71Sopenharmony_ci }); 68e41f4b71Sopenharmony_ci ``` 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci## storageStatistics.getTotalSizeOfVolume 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_cigetTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci异步获取外置存储设备中指定卷设备的总空间大小(单位为Byte),以callback方式返回。 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**参数:** 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 85e41f4b71Sopenharmony_ci | ---------- | ------------------------------------ | ---- | -------------------------- | 86e41f4b71Sopenharmony_ci | volumeUuid | string | 是 | 卷设备uuid | 87e41f4b71Sopenharmony_ci | callback | AsyncCallback<number> | 是 | 获取指定卷设备总空间之后的回调 | 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci**错误码:** 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 94e41f4b71Sopenharmony_ci| -------- | -------- | 95e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 96e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 97e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 98e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 99e41f4b71Sopenharmony_ci| 13600008 | No such object. | 100e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**示例:** 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci ```ts 105e41f4b71Sopenharmony_ci import volumemanager from "@ohos.file.volumeManager"; 106e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 107e41f4b71Sopenharmony_ci volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => { 108e41f4b71Sopenharmony_ci let uuid: string = volumes[0].uuid; 109e41f4b71Sopenharmony_ci storageStatistics.getTotalSizeOfVolume(uuid, (error: BusinessError, number: number) => { 110e41f4b71Sopenharmony_ci if (error) { 111e41f4b71Sopenharmony_ci console.error("getTotalSizeOfVolume failed with error:" + JSON.stringify(error)); 112e41f4b71Sopenharmony_ci } else { 113e41f4b71Sopenharmony_ci // do something 114e41f4b71Sopenharmony_ci console.info("getTotalSizeOfVolume successfully:" + number); 115e41f4b71Sopenharmony_ci } 116e41f4b71Sopenharmony_ci }); 117e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 118e41f4b71Sopenharmony_ci console.error("getAllVolumes failed with error:" + JSON.stringify(err)); 119e41f4b71Sopenharmony_ci }); 120e41f4b71Sopenharmony_ci ``` 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci## storageStatistics.getFreeSizeOfVolume 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_cigetFreeSizeOfVolume(volumeUuid: string): Promise<number> 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci异步获取外置存储设备中指定卷设备的可用空间大小(单位为Byte),以Promise方式返回。 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci**参数:** 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 137e41f4b71Sopenharmony_ci | ---------- | ------ | ---- | ---- | 138e41f4b71Sopenharmony_ci | volumeUuid | string | 是 | 卷设备uuid | 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci**返回值:** 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci | 类型 | 说明 | 143e41f4b71Sopenharmony_ci | --------------------- | ------------------ | 144e41f4b71Sopenharmony_ci | Promise<number> | Promise对象,返回指定卷的可用空间大小(单位为Byte) | 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci**错误码:** 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 151e41f4b71Sopenharmony_ci| -------- | -------- | 152e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 153e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 154e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 155e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 156e41f4b71Sopenharmony_ci| 13600008 | No such object. | 157e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci**示例:** 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci ```ts 162e41f4b71Sopenharmony_ci import volumemanager from "@ohos.file.volumeManager"; 163e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 164e41f4b71Sopenharmony_ci volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => { 165e41f4b71Sopenharmony_ci let uuid: string = volumes[0].uuid; 166e41f4b71Sopenharmony_ci storageStatistics.getFreeSizeOfVolume(uuid).then((number: number) => { 167e41f4b71Sopenharmony_ci console.info("getFreeSizeOfVolume successfully:" + number); 168e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 169e41f4b71Sopenharmony_ci console.error("getFreeSizeOfVolume failed with error:" + JSON.stringify(err)); 170e41f4b71Sopenharmony_ci }); 171e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 172e41f4b71Sopenharmony_ci console.error("getAllVolumes failed with error:" + JSON.stringify(err)); 173e41f4b71Sopenharmony_ci }); 174e41f4b71Sopenharmony_ci ``` 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci## storageStatistics.getFreeSizeOfVolume 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_cigetFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci异步获取外置存储设备中指定卷设备的可用空间大小(单位为Byte),以callback方式返回。 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci**参数:** 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 191e41f4b71Sopenharmony_ci | ---------- | ------------------------------------ | ---- | ---------------------------- | 192e41f4b71Sopenharmony_ci | volumeUuid | string | 是 | 卷设备uuid | 193e41f4b71Sopenharmony_ci | callback | AsyncCallback<number> | 是 | 获取指定卷可用空间之后的回调 | 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci**错误码:** 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 200e41f4b71Sopenharmony_ci| -------- | -------- | 201e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 202e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 203e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 204e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 205e41f4b71Sopenharmony_ci| 13600008 | No such object. | 206e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci**示例:** 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci ```ts 211e41f4b71Sopenharmony_ci import volumemanager from "@ohos.file.volumeManager"; 212e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 213e41f4b71Sopenharmony_ci volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => { 214e41f4b71Sopenharmony_ci let uuid: string = volumes[0].uuid; 215e41f4b71Sopenharmony_ci storageStatistics.getFreeSizeOfVolume(uuid, (error: BusinessError, number: number) => { 216e41f4b71Sopenharmony_ci if (error) { 217e41f4b71Sopenharmony_ci console.error("getFreeSizeOfVolume failed with error:" + JSON.stringify(error)); 218e41f4b71Sopenharmony_ci } else { 219e41f4b71Sopenharmony_ci // do something 220e41f4b71Sopenharmony_ci console.info("getFreeSizeOfVolume successfully: " + number); 221e41f4b71Sopenharmony_ci } 222e41f4b71Sopenharmony_ci }); 223e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 224e41f4b71Sopenharmony_ci console.error("getAllVolumes failed with error:" + JSON.stringify(err)); 225e41f4b71Sopenharmony_ci }); 226e41f4b71Sopenharmony_ci ``` 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci## storageStatistics.getBundleStats<sup>9+</sup> 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_cigetBundleStats(packageName: string, index?: number): Promise<BundleStats> 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci异步获取应用存储数据的空间大小(单位为Byte),以Promise方式返回。 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci**参数:** 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 243e41f4b71Sopenharmony_ci | ----------- | ------ | ---- | -------- | 244e41f4b71Sopenharmony_ci | packageName | string | 是 | 应用包名 | 245e41f4b71Sopenharmony_ci | index<sup>12+</sup> | number | 否 | 分身应用的索引号,默认值为0(表示未分身的主应用)。分身应用索引号在分身创建时默认占用从1开始且当前未被占用的最小索引号,并赋值给该应用的[BundleResourceInfo](../apis-ability-kit/js-apis-bundleManager-BundleResourceInfo-sys.md#bundleresourceinfo)的appIndex属性,后续可以通过调用[getBundleResourceInfo](../apis-ability-kit/js-apis-bundleResourceManager-sys.md#bundleresourcemanagergetbundleresourceinfo12)接口获得。| 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ci**返回值:** 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci | 类型 | 说明 | 250e41f4b71Sopenharmony_ci | ------------------------------------------ | -------------------------- | 251e41f4b71Sopenharmony_ci | Promise<[Bundlestats](js-apis-file-storage-statistics.md#bundlestats9)> | Promise对象,返回指定卷上的应用存储数据的空间大小(单位为Byte) | 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci**错误码:** 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 258e41f4b71Sopenharmony_ci| -------- | -------- | 259e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 260e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 261e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 262e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 263e41f4b71Sopenharmony_ci| 13600008 | No such object. | 264e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci**示例:** 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci ```ts 269e41f4b71Sopenharmony_ci import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 270e41f4b71Sopenharmony_ci import storageStatistics from "@ohos.file.storageStatistics"; 271e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 272e41f4b71Sopenharmony_ci import { hilog } from '@kit.PerformanceAnalysisKit'; 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ci let bundleName = "com.example.myapplication"; 275e41f4b71Sopenharmony_ci let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 276e41f4b71Sopenharmony_ci try { 277e41f4b71Sopenharmony_ci let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, bundleFlags); 278e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo.label)); 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci let packageName:string = bundleName; 281e41f4b71Sopenharmony_ci let index:number = resourceInfo.appIndex; 282e41f4b71Sopenharmony_ci storageStatistics.getBundleStats(packageName, index).then((BundleStats: storageStatistics.BundleStats) => { 283e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', 'getBundleStats successfully. BundleStats: %{public}s', JSON.stringify(BundleStats)); 284e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 285e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', 'getBundleStats failed with error: %{public}s', JSON.stringify(err)); 286e41f4b71Sopenharmony_ci }); 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ci } catch (err) { 289e41f4b71Sopenharmony_ci let message = (err as BusinessError).message; 290e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed with error: %{public}s', message); 291e41f4b71Sopenharmony_ci } 292e41f4b71Sopenharmony_ci ``` 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci## storageStatistics.getBundleStats<sup>9+</sup> 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_cigetBundleStats(packageName: string, callback: AsyncCallback<BundleStats>, index?: number): void 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci异步获取应用存储数据的空间大小(单位为Byte),以callback方式返回。 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci**参数:** 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 309e41f4b71Sopenharmony_ci | -------- | --------------------------------------------------------- | ---- | ------------------------------------ | 310e41f4b71Sopenharmony_ci | packageName | string | 是 | 应用包名 | 311e41f4b71Sopenharmony_ci | callback | AsyncCallback<[Bundlestats](js-apis-file-storage-statistics.md#bundlestats9)> | 是 | 获取指定卷上的应用存储数据的空间大小之后的回调 | 312e41f4b71Sopenharmony_ci | index<sup>12+</sup> | number | 否 | 分身应用的索引号,默认值为0(表示未分身的主应用)。分身应用索引号在分身创建时默认占用从1开始且当前未被占用的最小索引号,并赋值给该应用的[BundleResourceInfo](../apis-ability-kit/js-apis-bundleManager-BundleResourceInfo-sys.md#bundleresourceinfo)的appIndex属性,后续可以通过调用[getBundleResourceInfo](../apis-ability-kit/js-apis-bundleResourceManager-sys.md#bundleresourcemanagergetbundleresourceinfo12)接口获得。| 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci**错误码:** 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 319e41f4b71Sopenharmony_ci| -------- | -------- | 320e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 321e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 322e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 323e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 324e41f4b71Sopenharmony_ci| 13600008 | No such object. | 325e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci**示例:** 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci ```ts 330e41f4b71Sopenharmony_ci import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 331e41f4b71Sopenharmony_ci import storageStatistics from "@ohos.file.storageStatistics"; 332e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 333e41f4b71Sopenharmony_ci import { hilog } from '@kit.PerformanceAnalysisKit'; 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ci let bundleName = "com.example.myapplication"; 336e41f4b71Sopenharmony_ci let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 337e41f4b71Sopenharmony_ci try { 338e41f4b71Sopenharmony_ci let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, bundleFlags); 339e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo.label)); 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci let packageName:string = bundleName; 342e41f4b71Sopenharmony_ci let index:number = resourceInfo.appIndex; 343e41f4b71Sopenharmony_ci storageStatistics.getBundleStats(packageName, (err: BusinessError, BundleStats: storageStatistics.BundleStats) => { 344e41f4b71Sopenharmony_ci if (err) { 345e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', 'getBundleStats failed with error: %{public}s', JSON.stringify(err)); 346e41f4b71Sopenharmony_ci } else { 347e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', 'getBundleStats successfully. BundleStats: %{public}s', JSON.stringify(BundleStats)); 348e41f4b71Sopenharmony_ci } 349e41f4b71Sopenharmony_ci }, index); 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci } catch (err) { 352e41f4b71Sopenharmony_ci let message = (err as BusinessError).message; 353e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed: %{public}s', message); 354e41f4b71Sopenharmony_ci } 355e41f4b71Sopenharmony_ci ``` 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci## storageStatistics.getTotalSize<sup>9+</sup> 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_cigetTotalSize(): Promise<number> 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci获取内置存储的总空间大小(单位为Byte),以Promise方式返回。 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci**返回值:** 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_ci | 类型 | 说明 | 372e41f4b71Sopenharmony_ci | --------------------- | ------------------ | 373e41f4b71Sopenharmony_ci | Promise<number> | Promise对象,返回内置存储的总空间大小(单位为Byte) | 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ci**错误码:** 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 380e41f4b71Sopenharmony_ci| -------- | -------- | 381e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 382e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 383e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. | 384e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 385e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci**示例:** 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_ci ```ts 390e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 391e41f4b71Sopenharmony_ci storageStatistics.getTotalSize().then((number: number) => { 392e41f4b71Sopenharmony_ci console.info("getTotalSize successfully:" + JSON.stringify(number)); 393e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 394e41f4b71Sopenharmony_ci console.error("getTotalSize failed with error:"+ JSON.stringify(err)); 395e41f4b71Sopenharmony_ci }); 396e41f4b71Sopenharmony_ci ``` 397e41f4b71Sopenharmony_ci 398e41f4b71Sopenharmony_ci## storageStatistics.getTotalSize<sup>9+</sup> 399e41f4b71Sopenharmony_ci 400e41f4b71Sopenharmony_cigetTotalSize(callback: AsyncCallback<number>): void 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ci获取内置存储的总空间大小(单位为Byte),以callback方式返回。 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_ci**参数:** 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 413e41f4b71Sopenharmony_ci | -------- | ------------------------------------ | ---- | ------------------------ | 414e41f4b71Sopenharmony_ci | callback | AsyncCallback<number> | 是 | 获取内置存储的总空间大小之后的回调 | 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci**错误码:** 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 421e41f4b71Sopenharmony_ci| -------- | -------- | 422e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 423e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 424e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. | 425e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 426e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_ci**示例:** 429e41f4b71Sopenharmony_ci 430e41f4b71Sopenharmony_ci ```ts 431e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 432e41f4b71Sopenharmony_ci storageStatistics.getTotalSize((error: BusinessError, number: number) => { 433e41f4b71Sopenharmony_ci if (error) { 434e41f4b71Sopenharmony_ci console.error("getTotalSize failed with error:" + JSON.stringify(error)); 435e41f4b71Sopenharmony_ci } else { 436e41f4b71Sopenharmony_ci // do something 437e41f4b71Sopenharmony_ci console.info("getTotalSize successfully:" + number); 438e41f4b71Sopenharmony_ci } 439e41f4b71Sopenharmony_ci }); 440e41f4b71Sopenharmony_ci ``` 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_ci## storageStatistics.getTotalSizeSync<sup>10+</sup> 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_cigetTotalSizeSync(): number 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_ci同步获取内置存储的总空间大小(单位为Byte)。 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 451e41f4b71Sopenharmony_ci 452e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 453e41f4b71Sopenharmony_ci 454e41f4b71Sopenharmony_ci**返回值:** 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_ci | 类型 | 说明 | 457e41f4b71Sopenharmony_ci | --------------------- | ------------------ | 458e41f4b71Sopenharmony_ci | number | 返回内置存储的总空间大小(单位为Byte) | 459e41f4b71Sopenharmony_ci 460e41f4b71Sopenharmony_ci**错误码:** 461e41f4b71Sopenharmony_ci 462e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 463e41f4b71Sopenharmony_ci 464e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 465e41f4b71Sopenharmony_ci| -------- | -------- | 466e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 467e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 468e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. | 469e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 470e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 471e41f4b71Sopenharmony_ci 472e41f4b71Sopenharmony_ci**示例:** 473e41f4b71Sopenharmony_ci 474e41f4b71Sopenharmony_ci ```ts 475e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 476e41f4b71Sopenharmony_ci try { 477e41f4b71Sopenharmony_ci let number = storageStatistics.getTotalSizeSync(); 478e41f4b71Sopenharmony_ci console.info("getTotalSizeSync successfully:" + JSON.stringify(number)); 479e41f4b71Sopenharmony_ci } catch (err) { 480e41f4b71Sopenharmony_ci let error: BusinessError = err as BusinessError; 481e41f4b71Sopenharmony_ci console.error("getTotalSizeSync failed with error:" + JSON.stringify(error)); 482e41f4b71Sopenharmony_ci } 483e41f4b71Sopenharmony_ci ``` 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci## storageStatistics.getFreeSize<sup>9+</sup> 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_cigetFreeSize(): Promise<number> 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci获取内置存储的可用空间大小(单位为Byte),以Promise方式返回。 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_ci**返回值:** 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ci | 类型 | 说明 | 500e41f4b71Sopenharmony_ci | --------------------- | ------------------ | 501e41f4b71Sopenharmony_ci | Promise<number> | Promise对象,返回内置存储的可用空间大小(单位为Byte) | 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci**错误码:** 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 508e41f4b71Sopenharmony_ci| -------- | -------- | 509e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 510e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 511e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. | 512e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 513e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 514e41f4b71Sopenharmony_ci 515e41f4b71Sopenharmony_ci**示例:** 516e41f4b71Sopenharmony_ci 517e41f4b71Sopenharmony_ci ```ts 518e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 519e41f4b71Sopenharmony_ci storageStatistics.getFreeSize().then((number: number) => { 520e41f4b71Sopenharmony_ci console.info("getFreeSize successfully:" + JSON.stringify(number)); 521e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 522e41f4b71Sopenharmony_ci console.error("getFreeSize failed with error:" + JSON.stringify(err)); 523e41f4b71Sopenharmony_ci }); 524e41f4b71Sopenharmony_ci ``` 525e41f4b71Sopenharmony_ci 526e41f4b71Sopenharmony_ci## storageStatistics.getFreeSize<sup>9+</sup> 527e41f4b71Sopenharmony_ci 528e41f4b71Sopenharmony_cigetFreeSize(callback: AsyncCallback<number>): void 529e41f4b71Sopenharmony_ci 530e41f4b71Sopenharmony_ci获取内置存储的可用空间大小(单位为Byte),以callback方式返回。 531e41f4b71Sopenharmony_ci 532e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 535e41f4b71Sopenharmony_ci 536e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 537e41f4b71Sopenharmony_ci 538e41f4b71Sopenharmony_ci**参数:** 539e41f4b71Sopenharmony_ci 540e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 541e41f4b71Sopenharmony_ci | -------- | ------------------------------------ | ---- | ------------------------- | 542e41f4b71Sopenharmony_ci | callback | AsyncCallback<number> | 是 | 获取内置存储的可用空间大小之后的回调 | 543e41f4b71Sopenharmony_ci 544e41f4b71Sopenharmony_ci**错误码:** 545e41f4b71Sopenharmony_ci 546e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 547e41f4b71Sopenharmony_ci 548e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 549e41f4b71Sopenharmony_ci| -------- | -------- | 550e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 551e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 552e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. | 553e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 554e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 555e41f4b71Sopenharmony_ci 556e41f4b71Sopenharmony_ci**示例:** 557e41f4b71Sopenharmony_ci 558e41f4b71Sopenharmony_ci ```ts 559e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 560e41f4b71Sopenharmony_ci storageStatistics.getFreeSize((error: BusinessError, number: number) => { 561e41f4b71Sopenharmony_ci if (error) { 562e41f4b71Sopenharmony_ci console.error("getFreeSize failed with error:" + JSON.stringify(error)); 563e41f4b71Sopenharmony_ci } else { 564e41f4b71Sopenharmony_ci // do something 565e41f4b71Sopenharmony_ci console.info("getFreeSize successfully:" + number); 566e41f4b71Sopenharmony_ci } 567e41f4b71Sopenharmony_ci }); 568e41f4b71Sopenharmony_ci ``` 569e41f4b71Sopenharmony_ci 570e41f4b71Sopenharmony_ci## storageStatistics.getFreeSizeSync<sup>10+</sup> 571e41f4b71Sopenharmony_ci 572e41f4b71Sopenharmony_cigetFreeSizeSync(): number 573e41f4b71Sopenharmony_ci 574e41f4b71Sopenharmony_ci同步获取内置存储的可用空间大小(单位为Byte)。 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 577e41f4b71Sopenharmony_ci 578e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 579e41f4b71Sopenharmony_ci 580e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 581e41f4b71Sopenharmony_ci 582e41f4b71Sopenharmony_ci**返回值:** 583e41f4b71Sopenharmony_ci 584e41f4b71Sopenharmony_ci | 类型 | 说明 | 585e41f4b71Sopenharmony_ci | --------------------- | ------------------ | 586e41f4b71Sopenharmony_ci | number | 返回内置存储的可用空间大小(单位为Byte) | 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ci**错误码:** 589e41f4b71Sopenharmony_ci 590e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 591e41f4b71Sopenharmony_ci 592e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 593e41f4b71Sopenharmony_ci| -------- | -------- | 594e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 595e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 596e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. | 597e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 598e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_ci**示例:** 601e41f4b71Sopenharmony_ci 602e41f4b71Sopenharmony_ci ```ts 603e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 604e41f4b71Sopenharmony_ci try { 605e41f4b71Sopenharmony_ci let number = storageStatistics.getFreeSizeSync(); 606e41f4b71Sopenharmony_ci console.info("getFreeSizeSync successfully:" + JSON.stringify(number)); 607e41f4b71Sopenharmony_ci } catch (err) { 608e41f4b71Sopenharmony_ci let error: BusinessError = err as BusinessError; 609e41f4b71Sopenharmony_ci console.error("getFreeSizeSync failed with error:" + JSON.stringify(error)); 610e41f4b71Sopenharmony_ci } 611e41f4b71Sopenharmony_ci ``` 612e41f4b71Sopenharmony_ci 613e41f4b71Sopenharmony_ci## storageStatistics.getSystemSize<sup>9+</sup> 614e41f4b71Sopenharmony_ci 615e41f4b71Sopenharmony_cigetSystemSize(): Promise<number> 616e41f4b71Sopenharmony_ci 617e41f4b71Sopenharmony_ci异步获取系统数据的空间大小(单位为Byte),以Promise方式返回。 618e41f4b71Sopenharmony_ci 619e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 622e41f4b71Sopenharmony_ci 623e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 624e41f4b71Sopenharmony_ci 625e41f4b71Sopenharmony_ci**返回值:** 626e41f4b71Sopenharmony_ci 627e41f4b71Sopenharmony_ci | 类型 | 说明 | 628e41f4b71Sopenharmony_ci | --------------------- | ---------------- | 629e41f4b71Sopenharmony_ci | Promise<number> | Promise对象,返回系统数据的空间大小(单位为Byte) | 630e41f4b71Sopenharmony_ci 631e41f4b71Sopenharmony_ci**错误码:** 632e41f4b71Sopenharmony_ci 633e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 634e41f4b71Sopenharmony_ci 635e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 636e41f4b71Sopenharmony_ci| -------- | -------- | 637e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 638e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 639e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. | 640e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 641e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 642e41f4b71Sopenharmony_ci 643e41f4b71Sopenharmony_ci**示例:** 644e41f4b71Sopenharmony_ci 645e41f4b71Sopenharmony_ci ```ts 646e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 647e41f4b71Sopenharmony_ci storageStatistics.getSystemSize().then((number: number) => { 648e41f4b71Sopenharmony_ci console.info("getSystemSize successfully:" + number); 649e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 650e41f4b71Sopenharmony_ci console.error("getSystemSize failed with error:" + JSON.stringify(err)); 651e41f4b71Sopenharmony_ci }); 652e41f4b71Sopenharmony_ci ``` 653e41f4b71Sopenharmony_ci 654e41f4b71Sopenharmony_ci## storageStatistics.getSystemSize<sup>9+</sup> 655e41f4b71Sopenharmony_ci 656e41f4b71Sopenharmony_cigetSystemSize(callback: AsyncCallback<number>): void 657e41f4b71Sopenharmony_ci 658e41f4b71Sopenharmony_ci异步获取系统数据的空间大小(单位为Byte),以callback方式返回。 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 663e41f4b71Sopenharmony_ci 664e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 665e41f4b71Sopenharmony_ci 666e41f4b71Sopenharmony_ci**参数:** 667e41f4b71Sopenharmony_ci 668e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 669e41f4b71Sopenharmony_ci | ---------- | ------------------------------------ | ---- | -------------------------- | 670e41f4b71Sopenharmony_ci | callback | AsyncCallback<number> | 是 | 获取系统数据的空间大小之后的回调 | 671e41f4b71Sopenharmony_ci 672e41f4b71Sopenharmony_ci**错误码:** 673e41f4b71Sopenharmony_ci 674e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 675e41f4b71Sopenharmony_ci 676e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 677e41f4b71Sopenharmony_ci| -------- | -------- | 678e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 679e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 680e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. | 681e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 682e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 683e41f4b71Sopenharmony_ci 684e41f4b71Sopenharmony_ci**示例:** 685e41f4b71Sopenharmony_ci 686e41f4b71Sopenharmony_ci ```ts 687e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 688e41f4b71Sopenharmony_ci storageStatistics.getSystemSize((error: BusinessError, number: number) => { 689e41f4b71Sopenharmony_ci if (error) { 690e41f4b71Sopenharmony_ci console.error("getSystemSize failed with error:" + JSON.stringify(error)); 691e41f4b71Sopenharmony_ci } else { 692e41f4b71Sopenharmony_ci // do something 693e41f4b71Sopenharmony_ci console.info("getSystemSize successfully:" + number); 694e41f4b71Sopenharmony_ci } 695e41f4b71Sopenharmony_ci }); 696e41f4b71Sopenharmony_ci ``` 697e41f4b71Sopenharmony_ci 698e41f4b71Sopenharmony_ci## storageStatistics.getUserStorageStats<sup>9+</sup> 699e41f4b71Sopenharmony_ci 700e41f4b71Sopenharmony_cigetUserStorageStats(): Promise<StorageStats> 701e41f4b71Sopenharmony_ci 702e41f4b71Sopenharmony_ci异步获取当前用户各类别存储空间大小(单位为Byte),以Promise方式返回。 703e41f4b71Sopenharmony_ci 704e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 705e41f4b71Sopenharmony_ci 706e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 707e41f4b71Sopenharmony_ci 708e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 709e41f4b71Sopenharmony_ci 710e41f4b71Sopenharmony_ci**返回值:** 711e41f4b71Sopenharmony_ci 712e41f4b71Sopenharmony_ci | 类型 | 说明 | 713e41f4b71Sopenharmony_ci | --------------------- | ---------------- | 714e41f4b71Sopenharmony_ci | Promise<[StorageStats](#storagestats9)> | Promise对象,返回当前用户各类别存储空间大小(单位为Byte) | 715e41f4b71Sopenharmony_ci 716e41f4b71Sopenharmony_ci**错误码:** 717e41f4b71Sopenharmony_ci 718e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 719e41f4b71Sopenharmony_ci 720e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 721e41f4b71Sopenharmony_ci| -------- | -------- | 722e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 723e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 724e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 725e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 726e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 727e41f4b71Sopenharmony_ci 728e41f4b71Sopenharmony_ci**示例:** 729e41f4b71Sopenharmony_ci 730e41f4b71Sopenharmony_ci ```ts 731e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 732e41f4b71Sopenharmony_ci storageStatistics.getUserStorageStats().then((storageStats: storageStatistics.StorageStats) => { 733e41f4b71Sopenharmony_ci console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats)); 734e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 735e41f4b71Sopenharmony_ci console.error("getUserStorageStats failed with error:" + JSON.stringify(err)); 736e41f4b71Sopenharmony_ci }); 737e41f4b71Sopenharmony_ci ``` 738e41f4b71Sopenharmony_ci 739e41f4b71Sopenharmony_ci## storageStatistics.getUserStorageStats<sup>9+</sup> 740e41f4b71Sopenharmony_ci 741e41f4b71Sopenharmony_cigetUserStorageStats(callback: AsyncCallback<StorageStats>): void 742e41f4b71Sopenharmony_ci 743e41f4b71Sopenharmony_ci异步获取当前用户各类别存储空间大小(单位为Byte),以callback方式返回。 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_ci**参数:** 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 754e41f4b71Sopenharmony_ci | ---------- | ------------------------------------ | ---- | -------------------------- | 755e41f4b71Sopenharmony_ci | callback | AsyncCallback<[StorageStats](#storagestats9)> | 是 | 返回用户各类别存储空间大小之后的回调 | 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ci**错误码:** 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 760e41f4b71Sopenharmony_ci 761e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 762e41f4b71Sopenharmony_ci| -------- | -------- | 763e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 764e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 765e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 766e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 767e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 768e41f4b71Sopenharmony_ci 769e41f4b71Sopenharmony_ci**示例:** 770e41f4b71Sopenharmony_ci 771e41f4b71Sopenharmony_ci ```ts 772e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 773e41f4b71Sopenharmony_ci storageStatistics.getUserStorageStats((error: BusinessError, storageStats: storageStatistics.StorageStats) => { 774e41f4b71Sopenharmony_ci if (error) { 775e41f4b71Sopenharmony_ci console.error("getUserStorageStats failed with error:" + JSON.stringify(error)); 776e41f4b71Sopenharmony_ci } else { 777e41f4b71Sopenharmony_ci // do something 778e41f4b71Sopenharmony_ci console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats)); 779e41f4b71Sopenharmony_ci } 780e41f4b71Sopenharmony_ci }); 781e41f4b71Sopenharmony_ci ``` 782e41f4b71Sopenharmony_ci 783e41f4b71Sopenharmony_ci## storageStatistics.getUserStorageStats<sup>9+</sup> 784e41f4b71Sopenharmony_ci 785e41f4b71Sopenharmony_cigetUserStorageStats(userId: number): Promise<StorageStats> 786e41f4b71Sopenharmony_ci 787e41f4b71Sopenharmony_ci异步获取指定用户各类别存储空间大小(单位为Byte),以Promise方式返回。 788e41f4b71Sopenharmony_ci 789e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 790e41f4b71Sopenharmony_ci 791e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 792e41f4b71Sopenharmony_ci 793e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 794e41f4b71Sopenharmony_ci 795e41f4b71Sopenharmony_ci**参数:** 796e41f4b71Sopenharmony_ci 797e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 798e41f4b71Sopenharmony_ci | ---------- | ------ | ---- | ---- | 799e41f4b71Sopenharmony_ci | userId | number | 是 | 用户id| 800e41f4b71Sopenharmony_ci 801e41f4b71Sopenharmony_ci**返回值:** 802e41f4b71Sopenharmony_ci 803e41f4b71Sopenharmony_ci | 类型 | 说明 | 804e41f4b71Sopenharmony_ci | --------------------- | ---------------- | 805e41f4b71Sopenharmony_ci | Promise<[StorageStats](#storagestats9)> | Promise对象,返回指定用户各类别存储空间大小(单位为Byte) | 806e41f4b71Sopenharmony_ci 807e41f4b71Sopenharmony_ci**错误码:** 808e41f4b71Sopenharmony_ci 809e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 810e41f4b71Sopenharmony_ci 811e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 812e41f4b71Sopenharmony_ci| -------- | -------- | 813e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 814e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 815e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 816e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 817e41f4b71Sopenharmony_ci| 13600009 | User if out of range. | 818e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 819e41f4b71Sopenharmony_ci 820e41f4b71Sopenharmony_ci**示例:** 821e41f4b71Sopenharmony_ci 822e41f4b71Sopenharmony_ci ```ts 823e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 824e41f4b71Sopenharmony_ci let userId: number = 100; 825e41f4b71Sopenharmony_ci storageStatistics.getUserStorageStats(userId).then((storageStats: storageStatistics.StorageStats) => { 826e41f4b71Sopenharmony_ci console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats)); 827e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 828e41f4b71Sopenharmony_ci console.error("getUserStorageStats failed with error:" + JSON.stringify(err)); 829e41f4b71Sopenharmony_ci }); 830e41f4b71Sopenharmony_ci ``` 831e41f4b71Sopenharmony_ci 832e41f4b71Sopenharmony_ci## storageStatistics.getUserStorageStats<sup>9+</sup> 833e41f4b71Sopenharmony_ci 834e41f4b71Sopenharmony_cigetUserStorageStats(userId: number, callback: AsyncCallback<StorageStats>): void 835e41f4b71Sopenharmony_ci 836e41f4b71Sopenharmony_ci异步获取指定用户各类别存储空间大小(单位为Byte),以callback方式返回。 837e41f4b71Sopenharmony_ci 838e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.STORAGE_MANAGER 839e41f4b71Sopenharmony_ci 840e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 841e41f4b71Sopenharmony_ci 842e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 843e41f4b71Sopenharmony_ci 844e41f4b71Sopenharmony_ci**参数:** 845e41f4b71Sopenharmony_ci 846e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 847e41f4b71Sopenharmony_ci | ---------- | ------------------------------------ | ---- | -------------------------- | 848e41f4b71Sopenharmony_ci | userId | number | 是 | 用户id | 849e41f4b71Sopenharmony_ci | callback | AsyncCallback<[StorageStats](#storagestats9)> | 是 | 返回指定用户各类别存储空间大小之后的回调 | 850e41f4b71Sopenharmony_ci 851e41f4b71Sopenharmony_ci**错误码:** 852e41f4b71Sopenharmony_ci 853e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 854e41f4b71Sopenharmony_ci 855e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 856e41f4b71Sopenharmony_ci| -------- | -------- | 857e41f4b71Sopenharmony_ci| 201 | Permission verification failed. | 858e41f4b71Sopenharmony_ci| 202 | The caller is not a system application. | 859e41f4b71Sopenharmony_ci| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 860e41f4b71Sopenharmony_ci| 13600001 | IPC error. | 861e41f4b71Sopenharmony_ci| 13600009 | User if out of range. | 862e41f4b71Sopenharmony_ci| 13900042 | Unknown error. | 863e41f4b71Sopenharmony_ci 864e41f4b71Sopenharmony_ci**示例:** 865e41f4b71Sopenharmony_ci 866e41f4b71Sopenharmony_ci ```ts 867e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 868e41f4b71Sopenharmony_ci let userId: number = 100; 869e41f4b71Sopenharmony_ci storageStatistics.getUserStorageStats(userId, (error: BusinessError, storageStats: storageStatistics.StorageStats) => { 870e41f4b71Sopenharmony_ci if (error) { 871e41f4b71Sopenharmony_ci console.error("getUserStorageStats failed with error:" + JSON.stringify(error)); 872e41f4b71Sopenharmony_ci } else { 873e41f4b71Sopenharmony_ci // do something 874e41f4b71Sopenharmony_ci console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats)); 875e41f4b71Sopenharmony_ci } 876e41f4b71Sopenharmony_ci }); 877e41f4b71Sopenharmony_ci ``` 878e41f4b71Sopenharmony_ci 879e41f4b71Sopenharmony_ci## StorageStats<sup>9+</sup> 880e41f4b71Sopenharmony_ci 881e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 882e41f4b71Sopenharmony_ci 883e41f4b71Sopenharmony_ci**系统接口:** 该接口为系统接口。 884e41f4b71Sopenharmony_ci 885e41f4b71Sopenharmony_ci| 名称 | 类型 | 只读 | 可写 | 说明 | 886e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ----- | -------------- | 887e41f4b71Sopenharmony_ci| total | number | 是 | 否 | 内置存储总空间大小(单位为Byte) | 888e41f4b71Sopenharmony_ci| audio | number |是 | 否 | 音频数据大小 (单位为Byte) | 889e41f4b71Sopenharmony_ci| video | number | 是 | 否 | 视频数据大小(单位为Byte) | 890e41f4b71Sopenharmony_ci| image | number | 是 | 否 | 图像数据大小 (单位为Byte) | 891e41f4b71Sopenharmony_ci| file | number | 是 | 否 | 文件数据大小 (单位为Byte) | 892e41f4b71Sopenharmony_ci| app | number | 是 | 否 | 应用数据大小(单位为Byte) | 893