• 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> | Promise对象,返回指定卷设备的总空间大小(单位为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| 13900042 | 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| 13900042 | 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> | Promise对象,返回指定卷的可用空间大小(单位为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| 13900042 | 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| 13900042 | 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; | Promise对象,返回指定卷上的应用存储数据(单位为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| 13900042 | 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| 13900042 | 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; | Promise对象,返回指定卷上的应用存空间大小(单位为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| 13900042 | Unknown error. |
309
310**示例:**
311
312  ```js
313  storageStatistics.getCurrentBundleStats().then(function(BundleStats){
314      console.info("getCurrentBundleStats successfully:"+ JSON.stringify(BundleStats));
315  }).catch(function(err){
316      console.info("getCurrentBundleStats failed with error:"+ err);
317  });
318  ```
319
320## storageStatistics.getCurrentBundleStats<sup>9+</sup>
321
322getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void
323
324第三方应用异步获取当前应用存储空间大小(单位为Byte),以callback方式返回。
325
326**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
327
328**参数:**
329
330  | 参数名    | 类型                                                       | 必填  | 说明                                 |
331  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
332  | callback | AsyncCallback&lt;[BundleStats](#bundlestats9)&gt;          | 是   | 获取指定卷上的应用存储空间大小之后的回调        |
333
334**错误码:**
335
336以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。
337
338| 错误码ID | 错误信息 |
339| -------- | -------- |
340| 401 | The input parameter is invalid. |
341| 13600001 | IPC error. |
342| 13900042 | Unknown error. |
343
344**示例:**
345
346  ```js
347  storageStatistics.getCurrentBundleStats(function(error, bundleStats){
348      // do something
349      console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
350  });
351  ```
352
353## BundleStats<sup>9+</sup>
354
355**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
356
357| 名称      | 类型   | 可读 | 可写 | 说明           |
358| --------- | ------ | --- | ---- | -------------- |
359| appSize   | number | 是 | 否 | app数据大小(单位为Byte)    |
360| cacheSize | number | 是 | 否 | 缓存数据大小(单位为Byte)   |
361| dataSize  | number | 是 | 否 | 应用总数据大小(单位为Byte) |
362
363## storageStatistics.getTotalSize<sup>9+</sup>
364
365getTotalSize(): Promise&lt;number&gt;
366
367获取内置存储的总空间大小(单位为Byte),以promise方式返回。
368
369**需要权限**:ohos.permission.STORAGE_MANAGER
370
371**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
372
373**系统接口:** 该接口为系统接口。
374
375**返回值:**
376
377  | 类型                   | 说明               |
378  | --------------------- | ------------------ |
379  | Promise&lt;number&gt; | Promise对象,返回内置存储的总空间大小(单位为Byte)   |
380
381**错误码:**
382
383以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。
384
385| 错误码ID | 错误信息 |
386| -------- | -------- |
387| 201 | Permission verification failed. |
388| 202 | The caller is not a system application. |
389| 401 | The input parameter is invalid. |
390| 13600001 | IPC error. |
391| 13900042 | Unknown error. |
392
393**示例:**
394
395  ```js
396  storageStatistics.getTotalSize().then(function(number){
397      console.info("getTotalSize successfully:"+ JSON.stringify(number));
398  }).catch(function(err){
399      console.info("getTotalSize failed with error:"+ err);
400  });
401  ```
402
403## storageStatistics.getTotalSize<sup>9+</sup>
404
405getTotalSize(callback: AsyncCallback&lt;number&gt;): void
406
407获取内置存储的总空间大小(单位为Byte),以callback方式返回。
408
409**需要权限**:ohos.permission.STORAGE_MANAGER
410
411**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
412
413**系统接口:** 该接口为系统接口。
414
415**参数:**
416
417  | 参数名    | 类型                                  | 必填  | 说明                     |
418  | -------- | ------------------------------------ | ---- | ------------------------ |
419  | callback | AsyncCallback&lt;number&gt;          | 是   | 获取内置存储的总空间大小之后的回调 |
420
421**错误码:**
422
423以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。
424
425| 错误码ID | 错误信息 |
426| -------- | -------- |
427| 201 | Permission verification failed. |
428| 202 | The caller is not a system application. |
429| 401 | The input parameter is invalid. |
430| 13600001 | IPC error. |
431| 13900042 | Unknown error. |
432
433**示例:**
434
435  ```js
436  storageStatistics.getTotalSize(function(error, number){
437      // do something
438      console.info("getTotalSize successfully:"+ JSON.stringify(number));
439  });
440  ```
441
442## storageStatistics.getTotalSizeSync<sup>10+</sup>
443
444getTotalSizeSync(): number
445
446同步获取内置存储的总空间大小(单位为Byte)。
447
448**需要权限**:ohos.permission.STORAGE_MANAGER
449
450**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
451
452**系统接口:** 该接口为系统接口。
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| 13900042 | Unknown error. |
465
466**示例:**
467
468  ```js
469  try {
470    let number = storageStatistics.getTotalSizeSync();
471    console.info("getTotalSizeSync successfully:"+ JSON.stringify(number));
472  } catch (err) {
473    console.info("getTotalSizeSync failed with error:"+ err);
474  }
475  ```
476
477## storageStatistics.getFreeSize<sup>9+</sup>
478
479getFreeSize(): Promise&lt;number&gt;
480
481获取内置存储的可用空间大小(单位为Byte),以promise方式返回。
482
483**需要权限**:ohos.permission.STORAGE_MANAGER
484
485**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
486
487**系统接口:** 该接口为系统接口。
488
489**返回值:**
490
491  | 类型                   | 说明               |
492  | --------------------- | ------------------ |
493  | Promise&lt;number&gt; | Promise对象,返回内置存储的可用空间大小(单位为Byte) |
494
495**错误码:**
496
497以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。
498
499| 错误码ID | 错误信息 |
500| -------- | -------- |
501| 201 | Permission verification failed. |
502| 202 | The caller is not a system application. |
503| 401 | The input parameter is invalid. |
504| 13600001 | IPC error. |
505| 13900042 | Unknown error. |
506
507**示例:**
508
509  ```js
510  storageStatistics.getFreeSize().then(function(number){
511      console.info("getFreeSize successfully:"+ JSON.stringify(number));
512  }).catch(function(err){
513      console.info("getFreeSize failed with error:"+ err);
514  });
515  ```
516
517## storageStatistics.getFreeSize<sup>9+</sup>
518
519getFreeSize(callback: AsyncCallback&lt;number&gt;): void
520
521获取内置存储的可用空间大小(单位为Byte),以callback方式返回。
522
523**需要权限**:ohos.permission.STORAGE_MANAGER
524
525**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
526
527**系统接口:** 该接口为系统接口。
528
529**参数:**
530
531  | 参数名    | 类型                                  | 必填 | 说明                       |
532  | -------- | ------------------------------------ | ---- | ------------------------- |
533  | callback | AsyncCallback&lt;number&gt;          | 是   | 获取内置存储的可用空间大小之后的回调 |
534
535**错误码:**
536
537以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。
538
539| 错误码ID | 错误信息 |
540| -------- | -------- |
541| 201 | Permission verification failed. |
542| 202 | The caller is not a system application. |
543| 401 | The input parameter is invalid. |
544| 13600001 | IPC error. |
545| 13900042 | Unknown error. |
546
547**示例:**
548
549  ```js
550  storageStatistics.getFreeSize(function(error, number){
551      // do something
552      console.info("getFreeSize successfully:"+ JSON.stringify(number));
553  });
554  ```
555
556## storageStatistics.getFreeSizeSync<sup>10+</sup>
557
558getFreeSizeSync(): number
559
560同步获取内置存储的可用空间大小(单位为Byte)。
561
562**需要权限**:ohos.permission.STORAGE_MANAGER
563
564**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
565
566**系统接口:** 该接口为系统接口。
567
568**错误码:**
569
570以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。
571
572| 错误码ID | 错误信息 |
573| -------- | -------- |
574| 201 | Permission verification failed. |
575| 202 | The caller is not a system application. |
576| 401 | The input parameter is invalid. |
577| 13600001 | IPC error. |
578| 13900042 | Unknown error. |
579
580**示例:**
581
582  ```js
583  try {
584    let number = storageStatistics.getFreeSizeSync();
585    console.info("getFreeSizeSync successfully:"+ JSON.stringify(number));
586  } catch (err) {
587    console.info("getFreeSizeSync failed with error:"+ err);
588  }
589  ```
590
591## storageStatistics.getSystemSize<sup>9+</sup>
592
593getSystemSize(): Promise&lt;number&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;number&gt; | Promise对象,返回系统数据的空间大小(单位为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| 13900042 | Unknown error. |
620
621**示例:**
622
623  ```js
624  storageStatistics.getSystemSize().then(function(number){
625      console.info("getSystemSize successfully:"+ number);
626  }).catch(function(err){
627      console.info("getSystemSize failed with error:"+ err);
628  });
629  ```
630
631## storageStatistics.getSystemSize<sup>9+</sup>
632
633getSystemSize(callback: AsyncCallback&lt;number&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;number&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| 13900042 | Unknown error. |
660
661**示例:**
662
663  ```js
664  storageStatistics.getSystemSize(function(error, number){
665      // do something
666      console.info("getSystemSize successfully:"+ number);
667  });
668  ```
669
670## storageStatistics.getUserStorageStats<sup>9+</sup>
671
672getUserStorageStats(): 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  | Promise&lt;[StorageStats](#storagestats9)&gt; | Promise对象,返回当前用户各类别存储空间大小(单位为Byte) |
687
688**错误码:**
689
690以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。
691
692| 错误码ID | 错误信息 |
693| -------- | -------- |
694| 201 | Permission verification failed. |
695| 202 | The caller is not a system application. |
696| 401 | The input parameter is invalid. |
697| 13600001 | IPC error. |
698| 13900042 | Unknown error. |
699
700**示例:**
701
702  ```js
703  storageStatistics.getUserStorageStats().then(function(StorageStats){
704      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
705  }).catch(function(err){
706      console.info("getUserStorageStats failed with error:"+ err);
707  });
708  ```
709
710## storageStatistics.getUserStorageStats<sup>9+</sup>
711
712getUserStorageStats(callback: AsyncCallback&lt;StorageStats&gt;): void
713
714异步获取当前用户各类别存储空间大小(单位为Byte),以callback方式返回。
715
716**需要权限**:ohos.permission.STORAGE_MANAGER
717
718**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
719
720**系统接口:** 该接口为系统接口。
721
722**参数:**
723
724  | 参数名     | 类型                                 | 必填 | 说明                       |
725  | ---------- | ------------------------------------ | ---- | -------------------------- |
726  | callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | 是   | 返回用户各类别存储空间大小之后的回调 |
727
728**错误码:**
729
730以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。
731
732| 错误码ID | 错误信息 |
733| -------- | -------- |
734| 201 | Permission verification failed. |
735| 202 | The caller is not a system application. |
736| 401 | The input parameter is invalid. |
737| 13600001 | IPC error. |
738| 13900042 | Unknown error. |
739
740**示例:**
741
742  ```js
743  storageStatistics.getUserStorageStats(function(error, StorageStats){
744      // do something
745      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
746  });
747  ```
748
749## storageStatistics.getUserStorageStats<sup>9+</sup>
750
751getUserStorageStats(userId: number): Promise&lt;StorageStats&gt;
752
753异步获取指定用户各类别存储空间大小(单位为Byte),以promise方式返回。
754
755**需要权限**:ohos.permission.STORAGE_MANAGER
756
757**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
758
759**系统接口:** 该接口为系统接口。
760
761**参数:**
762
763  | 参数名     | 类型   | 必填 | 说明 |
764  | ---------- | ------ | ---- | ---- |
765  | userId | number | 是   | 用户id|
766
767**返回值:**
768
769  | 类型                  | 说明             |
770  | --------------------- | ---------------- |
771  | Promise&lt;[StorageStats](#storagestats9)&gt; | Promise对象,返回指定用户各类别存储空间大小(单位为Byte) |
772
773**错误码:**
774
775以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。
776
777| 错误码ID | 错误信息 |
778| -------- | -------- |
779| 201 | Permission verification failed. |
780| 202 | The caller is not a system application. |
781| 401 | The input parameter is invalid. |
782| 13600001 | IPC error. |
783| 13600009 | User if out of range. |
784| 13900042 | Unknown error. |
785
786**示例:**
787
788  ```js
789  let userId = 100;
790  storageStatistics.getUserStorageStats(userId).then(function(StorageStats){
791      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
792  }).catch(function(err){
793      console.info("getUserStorageStats failed with error:"+ err);
794  });
795  ```
796
797## storageStatistics.getUserStorageStats<sup>9+</sup>
798
799getUserStorageStats(userId: number, callback: AsyncCallback&lt;StorageStats&gt;): void
800
801异步获取指定用户各类别存储空间大小(单位为Byte),以callback方式返回。
802
803**需要权限**:ohos.permission.STORAGE_MANAGER
804
805**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
806
807**系统接口:** 该接口为系统接口。
808
809**参数:**
810
811  | 参数名     | 类型                                 | 必填 | 说明                       |
812  | ---------- | ------------------------------------ | ---- | -------------------------- |
813  | userId | number                               | 是   | 用户id |
814  | callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | 是   | 返回各类别数据大小之后的回调 |
815
816**错误码:**
817
818以下错误码的详细介绍请参见[文件管理错误码](../errorcodes/errorcode-filemanagement.md)。
819
820| 错误码ID | 错误信息 |
821| -------- | -------- |
822| 201 | Permission verification failed. |
823| 202 | The caller is not a system application. |
824| 401 | The input parameter is invalid. |
825| 13600001 | IPC error. |
826| 13600009 | User if out of range. |
827| 13900042 | Unknown error. |
828
829**示例:**
830
831  ```js
832  let userId = 100;
833  storageStatistics.getUserStorageStats(userId, function(error, StorageStats){
834      // do something
835      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
836  });
837  ```
838
839## StorageStats<sup>9+</sup>
840
841**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
842
843**系统接口:** 该接口为系统接口。
844
845| 名称      | 类型   | 可读  | 可写  | 说明           |
846| --------- | ------ | ---- | ----- | -------------- |
847| total   | number | 是 | 否 | 内置存储总空间大小(单位为Byte)    |
848| audio | number  |是 | 否 | 音频数据大小 (单位为Byte)  |
849| video  | number | 是 | 否 | 视频数据大小(单位为Byte) |
850| image   | number | 是 | 否 | 图像数据大小 (单位为Byte)   |
851| file | number | 是 | 否 | 文件数据大小 (单位为Byte)  |
852| app  | number | 是 | 否 | 应用数据大小(单位为Byte) |
853