1# @ohos.file.storageStatistics (应用空间统计)(系统接口) 2 3该模块提供空间查询相关的常用功能:包括对内外卡的空间查询、对应用分类数据统计的查询、对应用数据的查询等。 4 5> **说明:** 6> 7> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.file.storageStatistics (应用空间统计)](js-apis-file-storage-statistics.md)。 9 10## 导入模块 11 12```ts 13import storageStatistics from "@ohos.file.storageStatistics"; 14``` 15 16## storageStatistics.getTotalSizeOfVolume 17 18getTotalSizeOfVolume(volumeUuid: string): Promise<number> 19 20异步获取外置存储设备中指定卷设备的总空间大小(单位为Byte),以Promise方式返回。 21 22**需要权限**:ohos.permission.STORAGE_MANAGER 23 24**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 25 26**系统接口**:该接口为系统接口。 27 28**参数:** 29 30 | 参数名 | 类型 | 必填 | 说明 | 31 | ---------- | ------ | ---- | ---- | 32 | volumeUuid | string | 是 | 卷设备uuid。 | 33 34**返回值:** 35 36 | 类型 | 说明 | 37 | --------------------- | ---------------- | 38 | Promise<number> | Promise对象,返回指定卷设备的总空间大小(单位为Byte)。 | 39 40**错误码:** 41 42以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 43 44| 错误码ID | 错误信息 | 45| -------- | -------- | 46| 201 | Permission verification failed. | 47| 202 | The caller is not a system application. | 48| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 49| 13600001 | IPC error. | 50| 13600008 | No such object. | 51| 13900042 | Unknown error. | 52 53**示例:** 54 55 ```ts 56 import volumemanager from "@ohos.file.volumeManager"; 57 import { BusinessError } from '@ohos.base'; 58 volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => { 59 let uuid: string = volumes[0].uuid; 60 storageStatistics.getTotalSizeOfVolume(uuid).then((number: number) => { 61 console.info("getTotalSizeOfVolume successfully:" + number); 62 }).catch((err: BusinessError) => { 63 console.error("getTotalSizeOfVolume failed with error:" + JSON.stringify(err)); 64 }); 65 }).catch((err: BusinessError) => { 66 console.error("getAllVolumes failed with error:" + JSON.stringify(err)); 67 }); 68 ``` 69 70## storageStatistics.getTotalSizeOfVolume 71 72getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void 73 74异步获取外置存储设备中指定卷设备的总空间大小(单位为Byte),以callback方式返回。 75 76**需要权限**:ohos.permission.STORAGE_MANAGER 77 78**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 79 80**系统接口**:该接口为系统接口。 81 82**参数:** 83 84 | 参数名 | 类型 | 必填 | 说明 | 85 | ---------- | ------------------------------------ | ---- | -------------------------- | 86 | volumeUuid | string | 是 | 卷设备uuid。 | 87 | callback | AsyncCallback<number> | 是 | 获取指定卷设备总空间之后的回调。 | 88 89**错误码:** 90 91以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 92 93| 错误码ID | 错误信息 | 94| -------- | -------- | 95| 201 | Permission verification failed. | 96| 202 | The caller is not a system application. | 97| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 98| 13600001 | IPC error. | 99| 13600008 | No such object. | 100| 13900042 | Unknown error. | 101 102**示例:** 103 104 ```ts 105 import volumemanager from "@ohos.file.volumeManager"; 106 import { BusinessError } from '@ohos.base'; 107 volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => { 108 let uuid: string = volumes[0].uuid; 109 storageStatistics.getTotalSizeOfVolume(uuid, (error: BusinessError, number: number) => { 110 if (error) { 111 console.error("getTotalSizeOfVolume failed with error:" + JSON.stringify(error)); 112 } else { 113 // do something 114 console.info("getTotalSizeOfVolume successfully:" + number); 115 } 116 }); 117 }).catch((err: BusinessError) => { 118 console.error("getAllVolumes failed with error:" + JSON.stringify(err)); 119 }); 120 ``` 121 122## storageStatistics.getFreeSizeOfVolume 123 124getFreeSizeOfVolume(volumeUuid: string): Promise<number> 125 126异步获取外置存储设备中指定卷设备的可用空间大小(单位为Byte),以Promise方式返回。 127 128**需要权限**:ohos.permission.STORAGE_MANAGER 129 130**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 131 132**系统接口**:该接口为系统接口。 133 134**参数:** 135 136 | 参数名 | 类型 | 必填 | 说明 | 137 | ---------- | ------ | ---- | ---- | 138 | volumeUuid | string | 是 | 卷设备uuid。 | 139 140**返回值:** 141 142 | 类型 | 说明 | 143 | --------------------- | ------------------ | 144 | Promise<number> | Promise对象,返回指定卷的可用空间大小(单位为Byte)。 | 145 146**错误码:** 147 148以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 149 150| 错误码ID | 错误信息 | 151| -------- | -------- | 152| 201 | Permission verification failed. | 153| 202 | The caller is not a system application. | 154| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 155| 13600001 | IPC error. | 156| 13600008 | No such object. | 157| 13900042 | Unknown error. | 158 159**示例:** 160 161 ```ts 162 import volumemanager from "@ohos.file.volumeManager"; 163 import { BusinessError } from '@ohos.base'; 164 volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => { 165 let uuid: string = volumes[0].uuid; 166 storageStatistics.getFreeSizeOfVolume(uuid).then((number: number) => { 167 console.info("getFreeSizeOfVolume successfully:" + number); 168 }).catch((err: BusinessError) => { 169 console.error("getFreeSizeOfVolume failed with error:" + JSON.stringify(err)); 170 }); 171 }).catch((err: BusinessError) => { 172 console.error("getAllVolumes failed with error:" + JSON.stringify(err)); 173 }); 174 ``` 175 176## storageStatistics.getFreeSizeOfVolume 177 178getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void 179 180异步获取外置存储设备中指定卷设备的可用空间大小(单位为Byte),以callback方式返回。 181 182**需要权限**:ohos.permission.STORAGE_MANAGER 183 184**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 185 186**系统接口**:该接口为系统接口。 187 188**参数:** 189 190 | 参数名 | 类型 | 必填 | 说明 | 191 | ---------- | ------------------------------------ | ---- | ---------------------------- | 192 | volumeUuid | string | 是 | 卷设备uuid。 | 193 | callback | AsyncCallback<number> | 是 | 获取指定卷可用空间之后的回调。 | 194 195**错误码:** 196 197以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 198 199| 错误码ID | 错误信息 | 200| -------- | -------- | 201| 201 | Permission verification failed. | 202| 202 | The caller is not a system application. | 203| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 204| 13600001 | IPC error. | 205| 13600008 | No such object. | 206| 13900042 | Unknown error. | 207 208**示例:** 209 210 ```ts 211 import volumemanager from "@ohos.file.volumeManager"; 212 import { BusinessError } from '@ohos.base'; 213 volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => { 214 let uuid: string = volumes[0].uuid; 215 storageStatistics.getFreeSizeOfVolume(uuid, (error: BusinessError, number: number) => { 216 if (error) { 217 console.error("getFreeSizeOfVolume failed with error:" + JSON.stringify(error)); 218 } else { 219 // do something 220 console.info("getFreeSizeOfVolume successfully: " + number); 221 } 222 }); 223 }).catch((err: BusinessError) => { 224 console.error("getAllVolumes failed with error:" + JSON.stringify(err)); 225 }); 226 ``` 227 228## storageStatistics.getBundleStats<sup>9+</sup> 229 230getBundleStats(packageName: string, index?: number): Promise<BundleStats> 231 232异步获取应用存储数据的空间大小(单位为Byte),以Promise方式返回。 233 234**需要权限**:ohos.permission.STORAGE_MANAGER 235 236**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 237 238**系统接口**:该接口为系统接口。 239 240**参数:** 241 242 | 参数名 | 类型 | 必填 | 说明 | 243 | ----------- | ------ | ---- | -------- | 244 | packageName | string | 是 | 应用包名。 | 245 | 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)接口获得。| 246 247**返回值:** 248 249 | 类型 | 说明 | 250 | ------------------------------------------ | -------------------------- | 251 | Promise<[Bundlestats](js-apis-file-storage-statistics.md#bundlestats9)> | Promise对象,返回指定卷上的应用存储数据的空间大小(单位为Byte)。 | 252 253**错误码:** 254 255以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 256 257| 错误码ID | 错误信息 | 258| -------- | -------- | 259| 201 | Permission verification failed. | 260| 202 | The caller is not a system application. | 261| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 262| 13600001 | IPC error. | 263| 13600008 | No such object. | 264| 13900042 | Unknown error. | 265 266**示例:** 267 268 ```ts 269 import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 270 import storageStatistics from "@ohos.file.storageStatistics"; 271 import { BusinessError } from '@ohos.base'; 272 import { hilog } from '@kit.PerformanceAnalysisKit'; 273 274 let bundleName = "com.example.myapplication"; 275 let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 276 try { 277 let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, bundleFlags); 278 hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo.label)); 279 280 let packageName:string = bundleName; 281 let index:number = resourceInfo.appIndex; 282 storageStatistics.getBundleStats(packageName, index).then((BundleStats: storageStatistics.BundleStats) => { 283 hilog.info(0x0000, 'testTag', 'getBundleStats successfully. BundleStats: %{public}s', JSON.stringify(BundleStats)); 284 }).catch((err: BusinessError) => { 285 hilog.error(0x0000, 'testTag', 'getBundleStats failed with error: %{public}s', JSON.stringify(err)); 286 }); 287 288 } catch (err) { 289 let message = (err as BusinessError).message; 290 hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed with error: %{public}s', message); 291 } 292 ``` 293 294## storageStatistics.getBundleStats<sup>9+</sup> 295 296getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>, index?: number): void 297 298异步获取应用存储数据的空间大小(单位为Byte),以callback方式返回。 299 300**需要权限**:ohos.permission.STORAGE_MANAGER 301 302**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 303 304**系统接口**:该接口为系统接口。 305 306**参数:** 307 308 | 参数名 | 类型 | 必填 | 说明 | 309 | -------- | --------------------------------------------------------- | ---- | ------------------------------------ | 310 | packageName | string | 是 | 应用包名。 | 311 | callback | AsyncCallback<[Bundlestats](js-apis-file-storage-statistics.md#bundlestats9)> | 是 | 获取指定卷上的应用存储数据的空间大小之后的回调。 | 312 | 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)接口获得。| 313 314**错误码:** 315 316以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 317 318| 错误码ID | 错误信息 | 319| -------- | -------- | 320| 201 | Permission verification failed. | 321| 202 | The caller is not a system application. | 322| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 323| 13600001 | IPC error. | 324| 13600008 | No such object. | 325| 13900042 | Unknown error. | 326 327**示例:** 328 329 ```ts 330 import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 331 import storageStatistics from "@ohos.file.storageStatistics"; 332 import { BusinessError } from '@ohos.base'; 333 import { hilog } from '@kit.PerformanceAnalysisKit'; 334 335 let bundleName = "com.example.myapplication"; 336 let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 337 try { 338 let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, bundleFlags); 339 hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo.label)); 340 341 let packageName:string = bundleName; 342 let index:number = resourceInfo.appIndex; 343 storageStatistics.getBundleStats(packageName, (err: BusinessError, BundleStats: storageStatistics.BundleStats) => { 344 if (err) { 345 hilog.error(0x0000, 'testTag', 'getBundleStats failed with error: %{public}s', JSON.stringify(err)); 346 } else { 347 hilog.info(0x0000, 'testTag', 'getBundleStats successfully. BundleStats: %{public}s', JSON.stringify(BundleStats)); 348 } 349 }, index); 350 351 } catch (err) { 352 let message = (err as BusinessError).message; 353 hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed: %{public}s', message); 354 } 355 ``` 356 357## storageStatistics.getSystemSize<sup>9+</sup> 358 359getSystemSize(): Promise<number> 360 361异步获取系统数据的空间大小(单位为Byte),以Promise方式返回。 362 363**需要权限**:ohos.permission.STORAGE_MANAGER 364 365**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 366 367**系统接口**:该接口为系统接口。 368 369**返回值:** 370 371 | 类型 | 说明 | 372 | --------------------- | ---------------- | 373 | Promise<number> | Promise对象,返回系统数据的空间大小(单位为Byte)。 | 374 375**错误码:** 376 377以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 378 379| 错误码ID | 错误信息 | 380| -------- | -------- | 381| 201 | Permission verification failed. | 382| 202 | The caller is not a system application. | 383| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. | 384| 13600001 | IPC error. | 385| 13900042 | Unknown error. | 386 387**示例:** 388 389 ```ts 390 import { BusinessError } from '@ohos.base'; 391 storageStatistics.getSystemSize().then((number: number) => { 392 console.info("getSystemSize successfully:" + number); 393 }).catch((err: BusinessError) => { 394 console.error("getSystemSize failed with error:" + JSON.stringify(err)); 395 }); 396 ``` 397 398## storageStatistics.getSystemSize<sup>9+</sup> 399 400getSystemSize(callback: AsyncCallback<number>): void 401 402异步获取系统数据的空间大小(单位为Byte),以callback方式返回。 403 404**需要权限**:ohos.permission.STORAGE_MANAGER 405 406**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 407 408**系统接口**:该接口为系统接口。 409 410**参数:** 411 412 | 参数名 | 类型 | 必填 | 说明 | 413 | ---------- | ------------------------------------ | ---- | -------------------------- | 414 | callback | AsyncCallback<number> | 是 | 获取系统数据的空间大小之后的回调。 | 415 416**错误码:** 417 418以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 419 420| 错误码ID | 错误信息 | 421| -------- | -------- | 422| 201 | Permission verification failed. | 423| 202 | The caller is not a system application. | 424| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. | 425| 13600001 | IPC error. | 426| 13900042 | Unknown error. | 427 428**示例:** 429 430 ```ts 431 import { BusinessError } from '@ohos.base'; 432 storageStatistics.getSystemSize((error: BusinessError, number: number) => { 433 if (error) { 434 console.error("getSystemSize failed with error:" + JSON.stringify(error)); 435 } else { 436 // do something 437 console.info("getSystemSize successfully:" + number); 438 } 439 }); 440 ``` 441 442## storageStatistics.getUserStorageStats<sup>9+</sup> 443 444getUserStorageStats(): Promise<StorageStats> 445 446异步获取当前用户各类别存储空间大小(单位为Byte),以Promise方式返回。 447 448**需要权限**:ohos.permission.STORAGE_MANAGER 449 450**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 451 452**系统接口**:该接口为系统接口。 453 454**返回值:** 455 456 | 类型 | 说明 | 457 | --------------------- | ---------------- | 458 | Promise<[StorageStats](#storagestats9)> | Promise对象,返回当前用户各类别存储空间大小(单位为Byte)。 | 459 460**错误码:** 461 462以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 463 464| 错误码ID | 错误信息 | 465| -------- | -------- | 466| 201 | Permission verification failed. | 467| 202 | The caller is not a system application. | 468| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 469| 13600001 | IPC error. | 470| 13900042 | Unknown error. | 471 472**示例:** 473 474 ```ts 475 import { BusinessError } from '@ohos.base'; 476 storageStatistics.getUserStorageStats().then((storageStats: storageStatistics.StorageStats) => { 477 console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats)); 478 }).catch((err: BusinessError) => { 479 console.error("getUserStorageStats failed with error:" + JSON.stringify(err)); 480 }); 481 ``` 482 483## storageStatistics.getUserStorageStats<sup>9+</sup> 484 485getUserStorageStats(callback: AsyncCallback<StorageStats>): void 486 487异步获取当前用户各类别存储空间大小(单位为Byte),以callback方式返回。 488 489**需要权限**:ohos.permission.STORAGE_MANAGER 490 491**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 492 493**系统接口**:该接口为系统接口。 494 495**参数:** 496 497 | 参数名 | 类型 | 必填 | 说明 | 498 | ---------- | ------------------------------------ | ---- | -------------------------- | 499 | callback | AsyncCallback<[StorageStats](#storagestats9)> | 是 | 返回用户各类别存储空间大小之后的回调。 | 500 501**错误码:** 502 503以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 504 505| 错误码ID | 错误信息 | 506| -------- | -------- | 507| 201 | Permission verification failed. | 508| 202 | The caller is not a system application. | 509| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 510| 13600001 | IPC error. | 511| 13900042 | Unknown error. | 512 513**示例:** 514 515 ```ts 516 import { BusinessError } from '@ohos.base'; 517 storageStatistics.getUserStorageStats((error: BusinessError, storageStats: storageStatistics.StorageStats) => { 518 if (error) { 519 console.error("getUserStorageStats failed with error:" + JSON.stringify(error)); 520 } else { 521 // do something 522 console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats)); 523 } 524 }); 525 ``` 526 527## storageStatistics.getUserStorageStats<sup>9+</sup> 528 529getUserStorageStats(userId: number): Promise<StorageStats> 530 531异步获取指定用户各类别存储空间大小(单位为Byte),以Promise方式返回。 532 533**需要权限**:ohos.permission.STORAGE_MANAGER 534 535**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 536 537**系统接口**:该接口为系统接口。 538 539**参数:** 540 541 | 参数名 | 类型 | 必填 | 说明 | 542 | ---------- | ------ | ---- | ---- | 543 | userId | number | 是 | 用户id。| 544 545**返回值:** 546 547 | 类型 | 说明 | 548 | --------------------- | ---------------- | 549 | Promise<[StorageStats](#storagestats9)> | Promise对象,返回指定用户各类别存储空间大小(单位为Byte)。 | 550 551**错误码:** 552 553以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 554 555| 错误码ID | 错误信息 | 556| -------- | -------- | 557| 201 | Permission verification failed. | 558| 202 | The caller is not a system application. | 559| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 560| 13600001 | IPC error. | 561| 13600009 | User if out of range. | 562| 13900042 | Unknown error. | 563 564**示例:** 565 566 ```ts 567 import { BusinessError } from '@ohos.base'; 568 let userId: number = 100; 569 storageStatistics.getUserStorageStats(userId).then((storageStats: storageStatistics.StorageStats) => { 570 console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats)); 571 }).catch((err: BusinessError) => { 572 console.error("getUserStorageStats failed with error:" + JSON.stringify(err)); 573 }); 574 ``` 575 576## storageStatistics.getUserStorageStats<sup>9+</sup> 577 578getUserStorageStats(userId: number, callback: AsyncCallback<StorageStats>): void 579 580异步获取指定用户各类别存储空间大小(单位为Byte),以callback方式返回。 581 582**需要权限**:ohos.permission.STORAGE_MANAGER 583 584**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 585 586**系统接口**:该接口为系统接口。 587 588**参数:** 589 590 | 参数名 | 类型 | 必填 | 说明 | 591 | ---------- | ------------------------------------ | ---- | -------------------------- | 592 | userId | number | 是 | 用户id。 | 593 | callback | AsyncCallback<[StorageStats](#storagestats9)> | 是 | 返回指定用户各类别存储空间大小之后的回调。 | 594 595**错误码:** 596 597以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 598 599| 错误码ID | 错误信息 | 600| -------- | -------- | 601| 201 | Permission verification failed. | 602| 202 | The caller is not a system application. | 603| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 604| 13600001 | IPC error. | 605| 13600009 | User if out of range. | 606| 13900042 | Unknown error. | 607 608**示例:** 609 610 ```ts 611 import { BusinessError } from '@ohos.base'; 612 let userId: number = 100; 613 storageStatistics.getUserStorageStats(userId, (error: BusinessError, storageStats: storageStatistics.StorageStats) => { 614 if (error) { 615 console.error("getUserStorageStats failed with error:" + JSON.stringify(error)); 616 } else { 617 // do something 618 console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats)); 619 } 620 }); 621 ``` 622 623## StorageStats<sup>9+</sup> 624 625**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics 626 627**系统接口**:该接口为系统接口。 628 629| 名称 | 类型 | 只读 | 可写 | 说明 | 630| --------- | ------ | ---- | ----- | -------------- | 631| total | number | 是 | 否 | 内置存储总空间大小(单位为Byte)。 | 632| audio | number |是 | 否 | 音频数据大小 (单位为Byte)。 | 633| video | number | 是 | 否 | 视频数据大小(单位为Byte)。 | 634| image | number | 是 | 否 | 图像数据大小 (单位为Byte)。 | 635| file | number | 是 | 否 | 文件数据大小 (单位为Byte)。 | 636| app | number | 是 | 否 | 应用数据大小(单位为Byte)。 | 637