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