js-apis-storage-statistics.md 17.7 KB
Newer Older
A
Annie_wang 已提交
1
# @ohos.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
>
S
shawn_he 已提交
7
> 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.
A
Annie_wang 已提交
8

A
annie_wangli 已提交
9 10 11
## Modules to Import

```js
A
Annie_wang 已提交
12
import storageStatistics from "@ohos.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 20 21
Asynchronously obtains the total size of the specified volume. This API uses a promise to return the result.

**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

A
Annie_wang 已提交
26 27 28 29
This is a system API and cannot be called by third-party applications.


**Parameters**
A
annie_wangli 已提交
30

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

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

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

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

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

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

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

A
Annie_wang 已提交
56 57 58
Asynchronously obtains the total size of the specified volume. This API uses a callback to return the result.

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

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

A
Annie_wang 已提交
62

A
Annie_wang 已提交
63 64 65 66
This is a system API and cannot be called by third-party applications.


**Parameters**
A
annie_wangli 已提交
67

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

A
Annie_wang 已提交
73
**Example**
A
annie_wangli 已提交
74 75 76

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

A
Annie_wang 已提交
83
## storageStatistics.getFreeSizeOfVolume
A
annie_wangli 已提交
84 85 86

getFreeSizeOfVolume(volumeUuid: string): Promise<number>

A
Annie_wang 已提交
87
Asynchronously obtains the available space of the specified volume. This API uses a promise to return the result.
A
annie_wangli 已提交
88

A
Annie_wang 已提交
89 90
**Required permissions**: ohos.permission.STORAGE_MANAGER

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

A
Annie_wang 已提交
93

A
Annie_wang 已提交
94 95 96 97
This is a system API and cannot be called by third-party applications.


**Parameters**
A
annie_wangli 已提交
98

A
Annie_wang 已提交
99 100 101
  | Name    | Type  | Mandatory| Description|
  | ---------- | ------ | ---- | ---- |
  | volumeUuid | string | Yes  | UUID of the volume.|
A
annie_wangli 已提交
102

A
Annie_wang 已提交
103
**Return value**
A
annie_wangli 已提交
104

A
Annie_wang 已提交
105 106 107
  | Type                 | Description              |
  | --------------------- | ------------------ |
  | Promise<number> | Promise used to return the available space of the volume.|
A
annie_wangli 已提交
108

A
Annie_wang 已提交
109
**Example**
A
annie_wangli 已提交
110 111 112

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

A
Annie_wang 已提交
121
## storageStatistics.getFreeSizeOfVolume
A
annie_wangli 已提交
122

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

A
Annie_wang 已提交
125
Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result.
A
annie_wangli 已提交
126

A
Annie_wang 已提交
127 128
**Required permissions**: ohos.permission.STORAGE_MANAGER

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

A
Annie_wang 已提交
131

A
Annie_wang 已提交
132 133 134 135
This is a system API and cannot be called by third-party applications.


**Parameters**
A
annie_wangli 已提交
136

A
Annie_wang 已提交
137 138 139
  | Name    | Type                                | Mandatory| Description                        |
  | ---------- | ------------------------------------ | ---- | ---------------------------- |
  | volumeUuid | string                               | Yes  | UUID of the volume.                        |
A
Annie_wang 已提交
140
  | callback   | AsyncCallback<number>          | Yes  | Callback invoked to return the available space of the volume.|
A
annie_wangli 已提交
141

A
Annie_wang 已提交
142
**Example**
A
annie_wangli 已提交
143 144 145

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

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

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

A
Annie_wang 已提交
156
Asynchronously obtains space information of an application. This API uses a promise to return the result.
A
Annie_wang 已提交
157 158

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

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

A
Annie_wang 已提交
162

A
Annie_wang 已提交
163 164 165 166
This is a system API and cannot be called by third-party applications.


**Parameters**
A
annie_wangli 已提交
167

A
Annie_wang 已提交
168 169 170
  | Name     | Type  | Mandatory| Description    |
  | ----------- | ------ | ---- | -------- |
  | packageName | string | Yes  | Bundle name of the application.|
A
Annie_wang 已提交
171 172

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

A
Annie_wang 已提交
174 175
  | Type                                      | Description                      |
  | ------------------------------------------ | -------------------------- |
A
Annie_wang 已提交
176
  | Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise used to return the space information obtained.|
A
annie_wangli 已提交
177

A
Annie_wang 已提交
178
**Example**
A
annie_wangli 已提交
179 180 181

  ```js
  let packageName = "";
A
Annie_wang 已提交
182
  storageStatistics.getBundleStats(packageName).then(function(BundleStats){
A
annie_wangli 已提交
183 184 185 186 187 188
      console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
  }).catch(function(err){
      console.info("getBundleStats failed with error:"+ err);
  });
  ```

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

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

A
Annie_wang 已提交
193
Asynchronously obtains space information of an application. This API uses a callback to return the result.
A
Annie_wang 已提交
194 195

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

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

A
Annie_wang 已提交
199

A
Annie_wang 已提交
200 201 202 203
This is a system API and cannot be called by third-party applications.


**Parameters**
A
annie_wangli 已提交
204

A
Annie_wang 已提交
205 206 207
  | Name  | Type                                                     | Mandatory| Description                                |
  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
  | packageName | string | Yes  | Bundle name of the application.|
A
Annie_wang 已提交
208
  | callback | AsyncCallback&lt;[Bundlestats](#bundlestats9)&gt; | Yes  | Callback invoked to return the space information obtained.|
A
Annie_wang 已提交
209 210

**Example**
A
annie_wangli 已提交
211 212 213

  ```js
  let packageName = "";
A
Annie_wang 已提交
214
  storageStatistics.getBundleStats(packageName, function(error, BundleStats){
A
Annie_wang 已提交
215
      // Do something.
A
annie_wangli 已提交
216
      console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
A
annie_wangli 已提交
217 218 219
  });
  ```

A
Annie_wang 已提交
220
## storageStatistics.getCurrentBundleStats<sup>9+</sup>
A
Annie_wang 已提交
221

A
Annie_wang 已提交
222
getCurrentBundleStats(): Promise&lt;BundleStats&gt;
A
Annie_wang 已提交
223

A
Annie_wang 已提交
224
Asynchronously obtains space information of the current third-party application. This API uses a promise to return the result.
A
Annie_wang 已提交
225 226 227

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

A
Annie_wang 已提交
228
**Return value**
A
Annie_wang 已提交
229

A
Annie_wang 已提交
230 231
  | Type                                       | Description                      |
  | ------------------------------------------ | -------------------------- |
A
Annie_wang 已提交
232
  | Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise used to return the space information obtained.     |
A
Annie_wang 已提交
233

A
Annie_wang 已提交
234
**Example**
A
Annie_wang 已提交
235 236

  ```js
A
Annie_wang 已提交
237 238
  let bundleStats = storageStatistics.getCurrentBundleStats();
  console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
A
Annie_wang 已提交
239 240
  ```

A
Annie_wang 已提交
241
## storageStatistics.getCurrentBundleStats<sup>9+</sup>
A
Annie_wang 已提交
242

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

A
Annie_wang 已提交
245 246
Asynchronously obtains space information of the current third-party application. This API uses a callback to return the result.

A
Annie_wang 已提交
247 248
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
249
**Parameters**
A
Annie_wang 已提交
250

A
Annie_wang 已提交
251 252
  | Name   | Type                                                      | Mandatory | Description                                |
  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
A
Annie_wang 已提交
253
  | callback | AsyncCallback&lt;[BundleStats](#bundlestats9)&gt;          | Yes  | Callback invoked to return the space information obtained.       |
A
Annie_wang 已提交
254

A
Annie_wang 已提交
255
**Example**
A
Annie_wang 已提交
256 257

  ```js
A
Annie_wang 已提交
258
  storageStatistics.getCurrentBundleStats(function(error, bundleStats){
A
Annie_wang 已提交
259 260 261 262
      // Do something.
      console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
  });
  ```
A
Annie_wang 已提交
263

A
annie_wangli 已提交
264 265
## BundleStats<sup>9+</sup>

A
Annie_wang 已提交
266 267
### Attributes

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

A
Annie_wang 已提交
270 271 272

This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
273 274 275 276 277
| Name     | Type  | Readable| Writable| Description          |
| --------- | ------ | --- | ---- | -------------- |
| appSize   | number | Yes| No| Size of the application.   |
| cacheSize | number | Yes| No| Cache size of the application.  |
| dataSize  | number | Yes| No| Total data size of the application.|
A
Annie_wang 已提交
278 279


A
Annie_wang 已提交
280
## storageStatistics.getTotalSize<sup>9+</sup>
A
Annie_wang 已提交
281

A
Annie_wang 已提交
282
getTotalSize(): Promise&lt;number&gt;
A
Annie_wang 已提交
283 284 285 286 287 288 289 290

Obtains the total space of the built-in memory card. This API uses a promise to return the result.

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

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


A
Annie_wang 已提交
291 292 293 294
This is a system API and cannot be called by third-party applications.


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

A
Annie_wang 已提交
296 297 298
  | Type                  | Description              |
  | --------------------- | ------------------ |
  | Promise&lt;number&gt; | Promise used to return the total space of the built-in memory card.  |
A
Annie_wang 已提交
299

A
Annie_wang 已提交
300
**Example**
A
Annie_wang 已提交
301 302

  ```js
A
Annie_wang 已提交
303 304
  let number = storageStatistics.getTotalSize();
  console.info("getTotalSize successfully:"+ JSON.stringify(number));
A
Annie_wang 已提交
305 306
  ```

A
Annie_wang 已提交
307 308 309
## storageStatistics.getTotalSize<sup>9+</sup>

getTotalSize(callback: AsyncCallback&lt;number&gt;): void
A
Annie_wang 已提交
310 311 312 313 314 315 316 317

Obtains the total space of the built-in memory card. This API uses a callback to return the result.

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

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


A
Annie_wang 已提交
318 319 320 321
This is a system API and cannot be called by third-party applications.


**Parameters**
A
Annie_wang 已提交
322

A
Annie_wang 已提交
323 324
  | Name   | Type                                 | Mandatory | Description                    |
  | -------- | ------------------------------------ | ---- | ------------------------ |
A
Annie_wang 已提交
325
  | callback | AsyncCallback&lt;number&gt;          | Yes  | Callback invoked to return the total space of the built-in memory card.|
A
Annie_wang 已提交
326

A
Annie_wang 已提交
327
**Example**
A
Annie_wang 已提交
328 329

  ```js
A
Annie_wang 已提交
330
  storageStatistics.getTotalSize(function(error, number){
A
Annie_wang 已提交
331 332 333 334 335 336
      // Do something.
      console.info("getTotalSize successfully:"+ JSON.stringify(number));
  });
  ```


A
Annie_wang 已提交
337
## storageStatistics.getFreeSize<sup>9+</sup>
A
Annie_wang 已提交
338

A
Annie_wang 已提交
339
getFreeSize(): Promise&lt;number&gt;
A
Annie_wang 已提交
340 341 342 343 344 345 346 347

Obtains the available space of the built-in memory card. This API uses a promise to return the result.

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

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


A
Annie_wang 已提交
348 349 350 351
This is a system API and cannot be called by third-party applications.


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

A
Annie_wang 已提交
353 354 355
  | Type                  | Description              |
  | --------------------- | ------------------ |
  | Promise&lt;number&gt; | Promise used to return the available space of the built-in memory card.|
A
Annie_wang 已提交
356

A
Annie_wang 已提交
357
**Example**
A
Annie_wang 已提交
358 359

  ```js
A
Annie_wang 已提交
360 361
  let number = storageStatistics.getFreeSize();
  console.info("getFreeSize successfully:"+ JSON.stringify(number));
A
Annie_wang 已提交
362 363 364
  ```


A
Annie_wang 已提交
365
## storageStatistics.getFreeSize<sup>9+</sup>
A
Annie_wang 已提交
366

A
Annie_wang 已提交
367
getFreeSize(callback: AsyncCallback&lt;number&gt;): void
A
Annie_wang 已提交
368 369 370 371 372 373 374 375

Obtains the available space of the built-in memory card. This API uses a callback to return the result.

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

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


A
Annie_wang 已提交
376 377 378 379
This is a system API and cannot be called by third-party applications.


**Parameters**
A
Annie_wang 已提交
380

A
Annie_wang 已提交
381 382
  | Name   | Type                                 | Mandatory| Description                      |
  | -------- | ------------------------------------ | ---- | ------------------------- |
A
Annie_wang 已提交
383
  | callback | AsyncCallback&lt;number&gt;          | Yes  | Callback invoked to return the available space of the built-in memory card.|
A
Annie_wang 已提交
384

A
Annie_wang 已提交
385
**Example**
A
Annie_wang 已提交
386 387

  ```js
A
Annie_wang 已提交
388
  storageStatistics.getFreeSize(function(error, number){
A
Annie_wang 已提交
389 390 391 392 393
      // Do something.
      console.info("getFreeSize successfully:"+ JSON.stringify(number));
  });
  ```

A
Annie_wang 已提交
394
## storageStatistics.getSystemSize<sup>9+</sup>
A
Annie_wang 已提交
395 396 397 398 399 400 401 402 403 404

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

Asynchronously obtains the system space. This API uses a promise to return the result.

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

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


A
Annie_wang 已提交
405 406 407 408
This is a system API and cannot be called by third-party applications.


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

A
Annie_wang 已提交
410 411 412
  | Type                 | Description            |
  | --------------------- | ---------------- |
  | Promise&lt;number&gt; | Promise used to return the system space obtained.|
A
Annie_wang 已提交
413

A
Annie_wang 已提交
414
**Example**
A
Annie_wang 已提交
415 416

  ```js
A
Annie_wang 已提交
417
  storageStatistics.getSystemSize().then(function(number){
A
Annie_wang 已提交
418 419 420 421 422 423
      console.info("getSystemSize successfully:"+ number);
  }).catch(function(err){
      console.info("getSystemSize failed with error:"+ err);
  });
  ```

A
Annie_wang 已提交
424
## storageStatistics.getSystemSize<sup>9+</sup>
A
Annie_wang 已提交
425

A
Annie_wang 已提交
426
getSystemSize(callback: AsyncCallback&lt;number&gt;): void
A
Annie_wang 已提交
427 428 429 430 431 432 433 434

Asynchronously obtains the system space. This API uses a callback to return the result.

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

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


A
Annie_wang 已提交
435 436 437 438
This is a system API and cannot be called by third-party applications.


**Parameters**
A
Annie_wang 已提交
439

A
Annie_wang 已提交
440 441
  | Name    | Type                                | Mandatory| Description                      |
  | ---------- | ------------------------------------ | ---- | -------------------------- |
A
Annie_wang 已提交
442
  | callback   |  AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the system space obtained.|
A
Annie_wang 已提交
443

A
Annie_wang 已提交
444
**Example**
A
Annie_wang 已提交
445 446

  ```js
A
Annie_wang 已提交
447
  storageStatistics.getSystemSize(function(error, number){
A
Annie_wang 已提交
448 449 450 451 452
      // Do something.
      console.info("getSystemSize successfully:"+ number);
  });
  ```

A
Annie_wang 已提交
453 454
## storageStatistics.getUserStorageStats<sup>9+</sup>

A
Annie_wang 已提交
455
getUserStorageStats(userId?: number): Promise&lt;StorageStats&gt;
A
Annie_wang 已提交
456 457 458 459 460 461 462 463

Asynchronously obtains the space occupied by each type of user data. This API uses a promise to return the result.

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

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


A
Annie_wang 已提交
464 465 466 467
This is a system API and cannot be called by third-party applications.


**Parameters**
A
Annie_wang 已提交
468

A
Annie_wang 已提交
469 470 471
  | Name    | Type  | Mandatory| Description|
  | ---------- | ------ | ---- | ---- |
  | userId | number | No  | User ID.<br>Value:<br>-&nbsp; Set this parameter to the ID of the user to be queried.<br>-&nbsp; If no value is specified, information about the current user is queried.|
A
Annie_wang 已提交
472

A
Annie_wang 已提交
473
**Return value**
A
Annie_wang 已提交
474

A
Annie_wang 已提交
475 476
  | Type                 | Description            |
  | --------------------- | ---------------- |
A
Annie_wang 已提交
477
  | Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the information obtained.|
A
Annie_wang 已提交
478

A
Annie_wang 已提交
479
**Example**
A
Annie_wang 已提交
480 481

  ```js
A
Annie_wang 已提交
482
  let userId = 1;
A
Annie_wang 已提交
483
  storageStatistics.getUserStorageStats(userId).then(function(StorageStats){
A
Annie_wang 已提交
484 485 486 487 488 489
      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
  }).catch(function(err){
      console.info("getUserStorageStats failed with error:"+ err);
  });
  ```

A
Annie_wang 已提交
490
## storageStatistics.getUserStorageStats<sup>9+</sup>
A
Annie_wang 已提交
491

A
Annie_wang 已提交
492
getUserStorageStats(userId?: number, callback: AsyncCallback&lt;StorageStats&gt;): void
A
Annie_wang 已提交
493 494 495 496 497 498 499 500

Asynchronously obtains the space occupied by each type of user data. This API uses a callback to return the result.

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

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


A
Annie_wang 已提交
501 502 503 504
This is a system API and cannot be called by third-party applications.


**Parameters**
A
Annie_wang 已提交
505

A
Annie_wang 已提交
506 507 508
  | Name    | Type                                | Mandatory| Description                      |
  | ---------- | ------------------------------------ | ---- | -------------------------- |
  | userId | number                               | No  | User ID.<br>Value:<br>-&nbsp; Set this parameter to the ID of the user to be queried.<br>-&nbsp; If no value is specified, information about the current user is queried.                      |
A
Annie_wang 已提交
509
  | callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes  | Callback invoked to return the information obtained.|
A
Annie_wang 已提交
510

A
Annie_wang 已提交
511
**Example**
A
Annie_wang 已提交
512 513

  ```js
A
Annie_wang 已提交
514
  let userId = 1;
A
Annie_wang 已提交
515
  storageStatistics.getUserStorageStats(userId, function(error, StorageStats){
A
Annie_wang 已提交
516 517 518 519 520 521 522 523
      // Do something.
      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
  });
  ```


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

A
Annie_wang 已提交
524 525
### Attributes

A
Annie_wang 已提交
526 527
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
528 529 530

This is a system API and cannot be called by third-party applications.

A
Annie_wang 已提交
531 532 533 534 535 536 537 538
| Name     | Type  | Readable | Writable | Description          |
| --------- | ------ | ---- | ----- | -------------- |
| total   | number | Yes| No| Total space of the built-in memory card.   |
| audio | number  |Yes| No| Space occupied by audio data.  |
| video  | number | Yes| No| Space occupied by video data.|
| image   | number | Yes| No| Space occupied by image data.   |
| file | number | Yes| No| Space occupied by files.  |
| app  | number | Yes| No| Space occupied by application data.|