js-apis-file-storage-statistics.md 19.0 KB
Newer Older
A
Annie_wang 已提交
1
# @ohos.file.storageStatistics (Application Storage Statistics)
A
annie_wangli 已提交
2

A
Annie_wang 已提交
3 4
The **storageStatistics** module provides APIs for obtaining storage space information, including the space of built-in and plug-in memory cards, space occupied by different types of data, and space of application data.

S
shawn_he 已提交
5
> **NOTE**
A
annie_wangli 已提交
6
>
A
Annie_wang 已提交
7 8
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
A
annie_wangli 已提交
9 10 11
## Modules to Import

```js
A
Annie_wang 已提交
12
import storageStatistics from "@ohos.file.storageStatistics";
A
annie_wangli 已提交
13 14
```

A
Annie_wang 已提交
15
## storageStatistics.getTotalSizeOfVolume
A
annie_wangli 已提交
16 17 18

getTotalSizeOfVolume(volumeUuid: string): Promise<number>

A
Annie_wang 已提交
19
Obtains the total size (in bytes) of the specified volume in an external storage device. This API uses a promise to return the result.
A
Annie_wang 已提交
20 21

**Required permissions**: ohos.permission.STORAGE_MANAGER
A
annie_wangli 已提交
22

A
annie_wangli 已提交
23 24
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
25
**System API**: This is a system API.
A
Annie_wang 已提交
26 27 28


**Parameters**
A
annie_wangli 已提交
29

A
Annie_wang 已提交
30 31 32
  | Name    | Type  | Mandatory| Description|
  | ---------- | ------ | ---- | ---- |
  | volumeUuid | string | Yes  | UUID of the volume.|
A
annie_wangli 已提交
33

A
Annie_wang 已提交
34
**Return value**
A
annie_wangli 已提交
35

A
Annie_wang 已提交
36 37
  | Type                 | Description            |
  | --------------------- | ---------------- |
A
Annie_wang 已提交
38
  | Promise<number> | Promise used to return the total volume size obtained.|
A
annie_wangli 已提交
39

A
Annie_wang 已提交
40
**Example**
A
annie_wangli 已提交
41 42 43

  ```js
  let uuid = "";
A
Annie_wang 已提交
44
  storageStatistics.getTotalSizeOfVolume(uuid).then(function(number){
A
annie_wangli 已提交
45 46 47 48 49 50
      console.info("getTotalSizeOfVolume successfully:"+ number);
  }).catch(function(err){
      console.info("getTotalSizeOfVolume failed with error:"+ err);
  });
  ```

A
Annie_wang 已提交
51
## storageStatistics.getTotalSizeOfVolume
A
annie_wangli 已提交
52

A
Annie_wang 已提交
53
getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void
A
annie_wangli 已提交
54

A
Annie_wang 已提交
55
Obtains the total size (in bytes) of the specified volume in an external storage device. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
56 57

**Required permissions**: ohos.permission.STORAGE_MANAGER
A
annie_wangli 已提交
58

A
annie_wangli 已提交
59 60
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
61
**System API**: This is a system API.
A
Annie_wang 已提交
62 63 64


**Parameters**
A
annie_wangli 已提交
65

A
Annie_wang 已提交
66 67 68
  | Name    | Type                                | Mandatory| Description                      |
  | ---------- | ------------------------------------ | ---- | -------------------------- |
  | volumeUuid | string                               | Yes  | UUID of the volume.                      |
A
Annie_wang 已提交
69
  | callback   | AsyncCallback<number>          | Yes  | Callback invoked to return the total volume size obtained.|
A
annie_wangli 已提交
70

A
Annie_wang 已提交
71
**Example**
A
annie_wangli 已提交
72 73 74

  ```js
  let uuid = "";
A
Annie_wang 已提交
75
  storageStatistics.getTotalSizeOfVolume(uuid, function(error, number){
A
Annie_wang 已提交
76
      // Do something.
A
annie_wangli 已提交
77
      console.info("getTotalSizeOfVolume successfully:"+ number);
A
annie_wangli 已提交
78 79 80
  });
  ```

A
Annie_wang 已提交
81
## storageStatistics.getFreeSizeOfVolume
A
annie_wangli 已提交
82 83 84

getFreeSizeOfVolume(volumeUuid: string): Promise<number>

A
Annie_wang 已提交
85
Obtains the available space (in bytes) of the specified volume in an external storage device. This API uses a promise to return the result.
A
annie_wangli 已提交
86

A
Annie_wang 已提交
87 88
**Required permissions**: ohos.permission.STORAGE_MANAGER

A
annie_wangli 已提交
89 90
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
91
**System API**: This is a system API.
A
Annie_wang 已提交
92 93 94


**Parameters**
A
annie_wangli 已提交
95

A
Annie_wang 已提交
96 97 98
  | Name    | Type  | Mandatory| Description|
  | ---------- | ------ | ---- | ---- |
  | volumeUuid | string | Yes  | UUID of the volume.|
A
annie_wangli 已提交
99

A
Annie_wang 已提交
100
**Return value**
A
annie_wangli 已提交
101

A
Annie_wang 已提交
102 103
  | Type                 | Description              |
  | --------------------- | ------------------ |
A
Annie_wang 已提交
104
  | Promise<number> | Promise used to return the available volume space obtained.|
A
annie_wangli 已提交
105

A
Annie_wang 已提交
106
**Example**
A
annie_wangli 已提交
107 108 109

  ```js
  let uuid = "";
A
Annie_wang 已提交
110
  storageStatistics.getFreeSizeOfVolume(uuid).then(function(number){
A
annie_wangli 已提交
111 112 113 114 115 116 117
      console.info("getFreeSizeOfVolume successfully:"+ number);
  }).catch(function(err){
      console.info("getFreeSizeOfVolume failed with error:"+ err);
  });
  
  ```

A
Annie_wang 已提交
118
## storageStatistics.getFreeSizeOfVolume
A
annie_wangli 已提交
119

A
Annie_wang 已提交
120
getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void
A
annie_wangli 已提交
121

A
Annie_wang 已提交
122
Obtains the available space (in bytes) of the specified volume in an external storage device. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
123

A
Annie_wang 已提交
124 125
**Required permissions**: ohos.permission.STORAGE_MANAGER

A
annie_wangli 已提交
126 127
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
128
**System API**: This is a system API.
A
Annie_wang 已提交
129 130 131


**Parameters**
A
annie_wangli 已提交
132

A
Annie_wang 已提交
133 134 135
  | Name    | Type                                | Mandatory| Description                        |
  | ---------- | ------------------------------------ | ---- | ---------------------------- |
  | volumeUuid | string                               | Yes  | UUID of the volume.                        |
A
Annie_wang 已提交
136
  | callback   | AsyncCallback<number>          | Yes  | Callback invoked to return the available volume space obtained.|
A
annie_wangli 已提交
137

A
Annie_wang 已提交
138
**Example**
A
annie_wangli 已提交
139 140 141

  ```js
  let uuid = "";
A
Annie_wang 已提交
142
  storageStatistics.getFreeSizeOfVolume(uuid, function(error, number){
A
Annie_wang 已提交
143
      // Do something.
A
annie_wangli 已提交
144
      console.info("getFreeSizeOfVolume successfully:"+ number);
A
annie_wangli 已提交
145 146 147
  });
  ```

A
Annie_wang 已提交
148
## storageStatistics.getBundleStats<sup>9+</sup>
A
annie_wangli 已提交
149

A
annie_wangli 已提交
150
getBundleStats(packageName: string): Promise&lt;BundleStats&gt;
A
annie_wangli 已提交
151

A
Annie_wang 已提交
152
Obtains the space (in bytes) of an application. This API uses a promise to return the result.
A
Annie_wang 已提交
153 154

**Required permissions**: ohos.permission.STORAGE_MANAGER
A
annie_wangli 已提交
155 156

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
A
annie_wangli 已提交
157

A
Annie_wang 已提交
158
**System API**: This is a system API.
A
Annie_wang 已提交
159 160 161


**Parameters**
A
annie_wangli 已提交
162

A
Annie_wang 已提交
163 164 165
  | Name     | Type  | Mandatory| Description    |
  | ----------- | ------ | ---- | -------- |
  | packageName | string | Yes  | Bundle name of the application.|
A
Annie_wang 已提交
166 167

**Return value**
A
annie_wangli 已提交
168

A
Annie_wang 已提交
169 170
  | Type                                      | Description                      |
  | ------------------------------------------ | -------------------------- |
A
Annie_wang 已提交
171
  | Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise used to return the application space obtained.|
A
annie_wangli 已提交
172

A
Annie_wang 已提交
173
**Example**
A
annie_wangli 已提交
174 175 176

  ```js
  let packageName = "";
A
Annie_wang 已提交
177
  storageStatistics.getBundleStats(packageName).then(function(BundleStats){
A
annie_wangli 已提交
178 179 180 181 182 183
      console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
  }).catch(function(err){
      console.info("getBundleStats failed with error:"+ err);
  });
  ```

A
Annie_wang 已提交
184
## storageStatistics.getBundleStats<sup>9+</sup>
A
annie_wangli 已提交
185

A
annie_wangli 已提交
186
getBundleStats(packageName: string,  callback: AsyncCallback&lt;BundleStats&gt;): void
A
annie_wangli 已提交
187

A
Annie_wang 已提交
188
Obtains the space (in bytes) of an application. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
189 190

**Required permissions**: ohos.permission.STORAGE_MANAGER
A
annie_wangli 已提交
191

A
annie_wangli 已提交
192
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
A
annie_wangli 已提交
193

A
Annie_wang 已提交
194
**System API**: This is a system API.
A
Annie_wang 已提交
195 196 197


**Parameters**
A
annie_wangli 已提交
198

A
Annie_wang 已提交
199 200 201
  | Name  | Type                                                     | Mandatory| Description                                |
  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
  | packageName | string | Yes  | Bundle name of the application.|
A
Annie_wang 已提交
202
  | callback | AsyncCallback&lt;[Bundlestats](#bundlestats9)&gt; | Yes  | Callback invoked to return the application space obtained.|
A
Annie_wang 已提交
203 204

**Example**
A
annie_wangli 已提交
205 206 207

  ```js
  let packageName = "";
A
Annie_wang 已提交
208
  storageStatistics.getBundleStats(packageName, function(error, BundleStats){
A
Annie_wang 已提交
209
      // Do something.
A
annie_wangli 已提交
210
      console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
A
annie_wangli 已提交
211 212 213
  });
  ```

A
Annie_wang 已提交
214
## storageStatistics.getCurrentBundleStats<sup>9+</sup>
A
Annie_wang 已提交
215

A
Annie_wang 已提交
216
getCurrentBundleStats(): Promise&lt;BundleStats&gt;
A
Annie_wang 已提交
217

A
Annie_wang 已提交
218
Obtains the space (in bytes) of this third-party application. This API uses a promise to return the result.
A
Annie_wang 已提交
219 220 221

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
222
**Return value**
A
Annie_wang 已提交
223

A
Annie_wang 已提交
224 225
  | Type                                       | Description                      |
  | ------------------------------------------ | -------------------------- |
A
Annie_wang 已提交
226
  | Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise used to return the application space obtained.     |
A
Annie_wang 已提交
227

A
Annie_wang 已提交
228
**Example**
A
Annie_wang 已提交
229 230

  ```js
A
Annie_wang 已提交
231 232
  let bundleStats = storageStatistics.getCurrentBundleStats();
  console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
A
Annie_wang 已提交
233 234
  ```

A
Annie_wang 已提交
235
## storageStatistics.getCurrentBundleStats<sup>9+</sup>
A
Annie_wang 已提交
236

A
Annie_wang 已提交
237
getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void
A
Annie_wang 已提交
238

A
Annie_wang 已提交
239
Obtains the space (in bytes) of this third-party application. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
240

A
Annie_wang 已提交
241 242
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
243
**Parameters**
A
Annie_wang 已提交
244

A
Annie_wang 已提交
245 246
  | Name   | Type                                                      | Mandatory | Description                                |
  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
A
Annie_wang 已提交
247
  | callback | AsyncCallback&lt;[BundleStats](#bundlestats9)&gt;          | Yes  | Callback invoked to return the application space obtained.       |
A
Annie_wang 已提交
248

A
Annie_wang 已提交
249
**Example**
A
Annie_wang 已提交
250 251

  ```js
A
Annie_wang 已提交
252
  storageStatistics.getCurrentBundleStats(function(error, bundleStats){
A
Annie_wang 已提交
253 254 255 256
      // Do something.
      console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
  });
  ```
A
Annie_wang 已提交
257

A
annie_wangli 已提交
258 259 260
## BundleStats<sup>9+</sup>

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
A
annie_wangli 已提交
261

A
Annie_wang 已提交
262 263
| Name     | Type  | Readable| Writable| Description          |
| --------- | ------ | --- | ---- | -------------- |
A
Annie_wang 已提交
264 265 266
| appSize   | number | Yes| No| Size of the application, in bytes.   |
| cacheSize | number | Yes| No| Cache size of the application, in bytes.  |
| dataSize  | number | Yes| No| Total data size of the application, in bytes.|
A
Annie_wang 已提交
267 268


A
Annie_wang 已提交
269
## storageStatistics.getTotalSize<sup>9+</sup>
A
Annie_wang 已提交
270

A
Annie_wang 已提交
271
getTotalSize(): Promise&lt;number&gt;
A
Annie_wang 已提交
272

A
Annie_wang 已提交
273
Obtains the total size (in bytes) of the built-in storage. This API uses a promise to return the result.
A
Annie_wang 已提交
274 275 276 277 278

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
279
**System API**: This is a system API.
A
Annie_wang 已提交
280 281

**Return value**
A
Annie_wang 已提交
282

A
Annie_wang 已提交
283 284
  | Type                  | Description              |
  | --------------------- | ------------------ |
A
Annie_wang 已提交
285
  | Promise&lt;number&gt; | Promise used to return the built-in storage size obtained.  |
A
Annie_wang 已提交
286

A
Annie_wang 已提交
287
**Example**
A
Annie_wang 已提交
288 289

  ```js
A
Annie_wang 已提交
290 291
  let number = storageStatistics.getTotalSize();
  console.info("getTotalSize successfully:"+ JSON.stringify(number));
A
Annie_wang 已提交
292 293
  ```

A
Annie_wang 已提交
294 295 296
## storageStatistics.getTotalSize<sup>9+</sup>

getTotalSize(callback: AsyncCallback&lt;number&gt;): void
A
Annie_wang 已提交
297

A
Annie_wang 已提交
298
Obtains the total size (in bytes) of the built-in storage. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
299 300 301 302 303

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
304
**System API**: This is a system API.
A
Annie_wang 已提交
305 306

**Parameters**
A
Annie_wang 已提交
307

A
Annie_wang 已提交
308 309
  | Name   | Type                                 | Mandatory | Description                    |
  | -------- | ------------------------------------ | ---- | ------------------------ |
A
Annie_wang 已提交
310
  | callback | AsyncCallback&lt;number&gt;          | Yes  | Callback invoked to return the built-in storage size obtained.|
A
Annie_wang 已提交
311

A
Annie_wang 已提交
312
**Example**
A
Annie_wang 已提交
313 314

  ```js
A
Annie_wang 已提交
315
  storageStatistics.getTotalSize(function(error, number){
A
Annie_wang 已提交
316 317 318 319 320 321
      // Do something.
      console.info("getTotalSize successfully:"+ JSON.stringify(number));
  });
  ```


A
Annie_wang 已提交
322
## storageStatistics.getFreeSize<sup>9+</sup>
A
Annie_wang 已提交
323

A
Annie_wang 已提交
324
getFreeSize(): Promise&lt;number&gt;
A
Annie_wang 已提交
325

A
Annie_wang 已提交
326
Obtains the available space (in bytes) of the built-in storage. This API uses a promise to return the result.
A
Annie_wang 已提交
327 328 329 330 331

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
332
**System API**: This is a system API.
A
Annie_wang 已提交
333 334

**Return value**
A
Annie_wang 已提交
335

A
Annie_wang 已提交
336 337
  | Type                  | Description              |
  | --------------------- | ------------------ |
A
Annie_wang 已提交
338
  | Promise&lt;number&gt; | Promise used to return the available space of the built-in storage obtained.|
A
Annie_wang 已提交
339

A
Annie_wang 已提交
340
**Example**
A
Annie_wang 已提交
341 342

  ```js
A
Annie_wang 已提交
343 344
  let number = storageStatistics.getFreeSize();
  console.info("getFreeSize successfully:"+ JSON.stringify(number));
A
Annie_wang 已提交
345 346 347
  ```


A
Annie_wang 已提交
348
## storageStatistics.getFreeSize<sup>9+</sup>
A
Annie_wang 已提交
349

A
Annie_wang 已提交
350
getFreeSize(callback: AsyncCallback&lt;number&gt;): void
A
Annie_wang 已提交
351

A
Annie_wang 已提交
352
Obtains the available space (in bytes) of the built-in storage. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
353 354 355 356 357

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
358
**System API**: This is a system API.
A
Annie_wang 已提交
359 360

**Parameters**
A
Annie_wang 已提交
361

A
Annie_wang 已提交
362 363
  | Name   | Type                                 | Mandatory| Description                      |
  | -------- | ------------------------------------ | ---- | ------------------------- |
A
Annie_wang 已提交
364
  | callback | AsyncCallback&lt;number&gt;          | Yes  | Callback invoked to return the available space of the built-in storage obtained.|
A
Annie_wang 已提交
365

A
Annie_wang 已提交
366
**Example**
A
Annie_wang 已提交
367 368

  ```js
A
Annie_wang 已提交
369
  storageStatistics.getFreeSize(function(error, number){
A
Annie_wang 已提交
370 371 372 373 374
      // Do something.
      console.info("getFreeSize successfully:"+ JSON.stringify(number));
  });
  ```

A
Annie_wang 已提交
375
## storageStatistics.getSystemSize<sup>9+</sup>
A
Annie_wang 已提交
376 377 378

getSystemSize(): Promise&lt;number&gt;

A
Annie_wang 已提交
379
Obtains the system data space, in bytes. This API uses a promise to return the result.
A
Annie_wang 已提交
380 381 382 383 384

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
385
**System API**: This is a system API.
A
Annie_wang 已提交
386 387 388


**Return value**
A
Annie_wang 已提交
389

A
Annie_wang 已提交
390 391
  | Type                 | Description            |
  | --------------------- | ---------------- |
A
Annie_wang 已提交
392
  | Promise&lt;number&gt; | Promise used to return the system data space obtained.|
A
Annie_wang 已提交
393

A
Annie_wang 已提交
394
**Example**
A
Annie_wang 已提交
395 396

  ```js
A
Annie_wang 已提交
397
  storageStatistics.getSystemSize().then(function(number){
A
Annie_wang 已提交
398 399 400 401 402 403
      console.info("getSystemSize successfully:"+ number);
  }).catch(function(err){
      console.info("getSystemSize failed with error:"+ err);
  });
  ```

A
Annie_wang 已提交
404
## storageStatistics.getSystemSize<sup>9+</sup>
A
Annie_wang 已提交
405

A
Annie_wang 已提交
406
getSystemSize(callback: AsyncCallback&lt;number&gt;): void
A
Annie_wang 已提交
407

A
Annie_wang 已提交
408
Obtains the system data space, in bytes. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
409 410 411 412 413

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
414
**System API**: This is a system API.
A
Annie_wang 已提交
415 416

**Parameters**
A
Annie_wang 已提交
417

A
Annie_wang 已提交
418 419
  | Name    | Type                                | Mandatory| Description                      |
  | ---------- | ------------------------------------ | ---- | -------------------------- |
A
Annie_wang 已提交
420
  | callback   |  AsyncCallback&lt;number&gt;         | Yes  | Callback invoked to return the system data space obtained.|
A
Annie_wang 已提交
421

A
Annie_wang 已提交
422
**Example**
A
Annie_wang 已提交
423 424

  ```js
A
Annie_wang 已提交
425
  storageStatistics.getSystemSize(function(error, number){
A
Annie_wang 已提交
426 427 428 429 430
      // Do something.
      console.info("getSystemSize successfully:"+ number);
  });
  ```

A
Annie_wang 已提交
431 432
## storageStatistics.getUserStorageStats<sup>9+</sup>

A
Annie_wang 已提交
433 434 435 436 437 438 439 440
getUserStorageStats(): Promise&lt;StorageStats&gt;

Obtains the storage statistics (in bytes) of this user. This API uses a promise to return the result.

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
441
**System API**: This is a system API.
A
Annie_wang 已提交
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468

**Return value**

  | Type                 | Description            |
  | --------------------- | ---------------- |
  | Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the information obtained.|

**Example**

  ```js
  storageStatistics.getUserStorageStats().then(function(StorageStats){
      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
  }).catch(function(err){
      console.info("getUserStorageStats failed with error:"+ err);
  });
  ```

## storageStatistics.getUserStorageStats<sup>9+</sup>

getUserStorageStats(callback: AsyncCallback&lt;StorageStats&gt;): void

Obtains the storage statistics (in bytes) of this user. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
469
**System API**: This is a system API.
A
Annie_wang 已提交
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485

**Parameters**

  | Name    | Type                                | Mandatory| Description                      |
  | ---------- | ------------------------------------ | ---- | -------------------------- |
  | callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes  | Callback invoked to return the information obtained.|

**Example**

  ```js
  storageStatistics.getUserStorageStats(function(error, StorageStats){
      // Do something.
      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
  });
  ```
getUserStorageStats(userId: number): Promise&lt;StorageStats&gt;
A
Annie_wang 已提交
486

A
Annie_wang 已提交
487
Obtains the storage statistics (in bytes) of the specified user. This API uses a promise to return the result.
A
Annie_wang 已提交
488 489 490 491 492

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
493
**System API**: This is a system API.
A
Annie_wang 已提交
494 495

**Parameters**
A
Annie_wang 已提交
496

A
Annie_wang 已提交
497 498
  | Name    | Type  | Mandatory| Description|
  | ---------- | ------ | ---- | ---- |
A
Annie_wang 已提交
499
  | userId | number | Yes  | User ID.|
A
Annie_wang 已提交
500

A
Annie_wang 已提交
501
**Return value**
A
Annie_wang 已提交
502

A
Annie_wang 已提交
503 504
  | Type                 | Description            |
  | --------------------- | ---------------- |
A
Annie_wang 已提交
505
  | Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the information obtained.|
A
Annie_wang 已提交
506

A
Annie_wang 已提交
507
**Example**
A
Annie_wang 已提交
508 509

  ```js
A
Annie_wang 已提交
510
  let userId = 100;
A
Annie_wang 已提交
511
  storageStatistics.getUserStorageStats(userId).then(function(StorageStats){
A
Annie_wang 已提交
512 513 514 515 516 517
      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
  }).catch(function(err){
      console.info("getUserStorageStats failed with error:"+ err);
  });
  ```

A
Annie_wang 已提交
518
## storageStatistics.getUserStorageStats<sup>9+</sup>
A
Annie_wang 已提交
519

A
Annie_wang 已提交
520
getUserStorageStats(userId: number, callback: AsyncCallback&lt;StorageStats&gt;): void
A
Annie_wang 已提交
521

A
Annie_wang 已提交
522
Obtains the storage statistics (in bytes) of the specified user. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
523 524 525 526 527

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
528
**System API**: This is a system API.
A
Annie_wang 已提交
529 530

**Parameters**
A
Annie_wang 已提交
531

A
Annie_wang 已提交
532 533
  | Name    | Type                                | Mandatory| Description                      |
  | ---------- | ------------------------------------ | ---- | -------------------------- |
A
Annie_wang 已提交
534
  | userId | number                               | Yes  | User ID.|
A
Annie_wang 已提交
535
  | callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes  | Callback invoked to return the information obtained.|
A
Annie_wang 已提交
536

A
Annie_wang 已提交
537
**Example**
A
Annie_wang 已提交
538 539

  ```js
A
Annie_wang 已提交
540
  let userId = 100;
A
Annie_wang 已提交
541
  storageStatistics.getUserStorageStats(userId, function(error, StorageStats){
A
Annie_wang 已提交
542 543 544 545 546 547 548 549 550 551
      // Do something.
      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
  });
  ```


## StorageStats<sup>9+</sup>

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
552
**System API**: This is a system API.
A
Annie_wang 已提交
553

A
Annie_wang 已提交
554 555
| Name     | Type  | Readable | Writable | Description          |
| --------- | ------ | ---- | ----- | -------------- |
A
Annie_wang 已提交
556 557 558 559 560 561
| total   | number | Yes| No| Total size of the built-in storage, in bytes.   |
| audio | number  |Yes| No| Space occupied by audio data, in bytes. |
| video  | number | Yes| No| Space occupied by video data, in bytes.|
| image   | number | Yes| No| Space occupied by image data, in bytes.  |
| file | number | Yes| No| Space occupied by files, in bytes. |
| app  | number | Yes| No| Space occupied by application data, in bytes.|