js-apis-storage-statistics.md 6.9 KB
Newer Older
A
annie_wangli 已提交
1 2
# App Storage Statistics

A
Annie_wang 已提交
3
> **NOTE**<br/>
A
annie_wangli 已提交
4
>
A
annie_wangli 已提交
5
> - 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 已提交
6 7 8 9
> - API version 9 is a canary version for trial use. The APIs of this version may be unstable.
> - The APIs of this module are system APIs and cannot be called by third-party applications.

This module provides functions to obtain storage statistics, including the space of built-in and plug-in memory cards, statistics of application data by type, and application data.
A
annie_wangli 已提交
10 11 12 13

## Modules to Import

```js
A
annie_wangli 已提交
14
import storagestatistics from "@ohos.storageStatistics";
A
annie_wangli 已提交
15 16 17 18 19 20
```

## storagestatistics.getTotalSizeOfVolume

getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;

A
Annie_wang 已提交
21
Asynchronously obtains the total space of the specified volume. This API uses a promise to return the result.
A
annie_wangli 已提交
22

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

A
annie_wangli 已提交
25 26
- Parameters

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

- Return value

A
annie_wangli 已提交
33
  | Type                 | Description            |
A
annie_wangli 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  | --------------------- | ---------------- |
  | Promise&lt;number&gt; | Promise used to return the total space of the volume.|

- Example

  ```js
  let uuid = "";
  storagestatistics.getTotalSizeOfVolume(uuid).then(function(number){
      console.info("getTotalSizeOfVolume successfully:"+ number);
  }).catch(function(err){
      console.info("getTotalSizeOfVolume failed with error:"+ err);
  });
  ```

## storagestatistics.getTotalSizeOfVolume

getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void

A
Annie_wang 已提交
52
Asynchronously obtains the total space of the specified volume. This API uses a callback to return the result.
A
annie_wangli 已提交
53

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

A
annie_wangli 已提交
56 57
- Parameters

A
annie_wangli 已提交
58
  | Name    | Type                                | Mandatory| Description                      |
A
annie_wangli 已提交
59
  | ---------- | ------------------------------------ | ---- | -------------------------- |
A
annie_wangli 已提交
60 61
  | volumeUuid | string                               | Yes  | UUID of the volume.                      |
  | callback   | callback:AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the total space of the volume.|
A
annie_wangli 已提交
62 63 64 65 66 67

- Example

  ```js
  let uuid = "";
  storagestatistics.getTotalSizeOfVolume(uuid, function(error, number){
A
Annie_wang 已提交
68
      // Do something.
A
annie_wangli 已提交
69
      console.info("getTotalSizeOfVolume successfully:"+ number);
A
annie_wangli 已提交
70 71
  });
  ```
A
annie_wangli 已提交
72
  
A
annie_wangli 已提交
73 74 75 76 77 78
  

## storagestatistics.getFreeSizeOfVolume

getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;

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

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

A
annie_wangli 已提交
83 84
- Parameters

A
annie_wangli 已提交
85
  | Name    | Type  | Mandatory| Description|
A
annie_wangli 已提交
86
  | ---------- | ------ | ---- | ---- |
A
annie_wangli 已提交
87
  | volumeUuid | string | Yes  | UUID of the volume.|
A
annie_wangli 已提交
88 89 90

- Return value

A
annie_wangli 已提交
91
  | Type                 | Description              |
A
annie_wangli 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
  | --------------------- | ------------------ |
  | Promise&lt;number&gt; | Promise used to return the available space of the volume.|

- Example

  ```js
  let uuid = "";
  storagestatistics.getFreeSizeOfVolume(uuid).then(function(number){
      console.info("getFreeSizeOfVolume successfully:"+ number);
  }).catch(function(err){
      console.info("getFreeSizeOfVolume failed with error:"+ err);
  });
  
  ```

## storagestatistics.getFreeSizeOfVolume

getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void

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

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

A
annie_wangli 已提交
115 116
- Parameters

A
annie_wangli 已提交
117
  | Name    | Type                                | Mandatory| Description                        |
A
annie_wangli 已提交
118
  | ---------- | ------------------------------------ | ---- | ---------------------------- |
A
annie_wangli 已提交
119 120
  | volumeUuid | string                               | Yes  | UUID of the volume.                        |
  | callback   | callback:AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the available space of the volume.|
A
annie_wangli 已提交
121 122 123 124 125 126

- Example

  ```js
  let uuid = "";
  storagestatistics.getFreeSizeOfVolume(uuid, function(error, number){
A
Annie_wang 已提交
127
      // Do something.
A
annie_wangli 已提交
128
      console.info("getFreeSizeOfVolume successfully:"+ number);
A
annie_wangli 已提交
129 130
  });
  ```
A
Annie_wang 已提交
131 132 133 134 135

## storagestatistics.getBundleStats<sup>9+</sup>

getBundleStats(packageName: string): Promise&lt;BundleStats&gt;

A
Annie_wang 已提交
136
Asynchronously obtains application information. This API uses a promise to return the result.
A
Annie_wang 已提交
137 138 139 140 141 142 143

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

- Parameters

  | Name     | Type  | Mandatory| Description    |
  | ----------- | ------ | ---- | -------- |
A
Annie_wang 已提交
144
  | packageName | string | Yes  | Bundle name of the application.|
A
Annie_wang 已提交
145 146 147 148 149
  
- Return value

  | Type                                      | Description                      |
  | ------------------------------------------ | -------------------------- |
A
Annie_wang 已提交
150
  | Promise&lt;[Bundlestats](#bundlestats)&gt; | Promise used to return the application data obtained.|
A
Annie_wang 已提交
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

- Example

  ```js
  let packageName = "";
  storagestatistics.getBundleStats(packageName).then(function(BundleStats){
      console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
  }).catch(function(err){
      console.info("getBundleStats failed with error:"+ err);
  });
  ```

## storagestatistics.getBundleStats<sup>9+</sup>

getBundleStats(packageName: string,  callback: AsyncCallback&lt;BundleStats&gt;): void

A
Annie_wang 已提交
167
Asynchronously obtains application information. This API uses a callback to return the result.
A
Annie_wang 已提交
168 169 170 171 172 173 174

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

- Parameters

  | Name  | Type                                                     | Mandatory| Description                                |
  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
A
Annie_wang 已提交
175 176
  | packageName | string | Yes  | Bundle name of the application.|
  | callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | Yes  | Callback used to return the application information obtained.|
A
Annie_wang 已提交
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
  
- Example

  ```js
  let packageName = "";
  storagestatistics.getBundleStats(packageName, function(error, BundleStats){
      // Do something.
      console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
  });
  ```

## BundleStats<sup>9+</sup>

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

A
Annie_wang 已提交
192
### Attribute
A
Annie_wang 已提交
193 194 195

| Name     | Type  | Description          |
| --------- | ------ | -------------- |
A
Annie_wang 已提交
196 197 198
| appSize<sup>9+</sup>   | number | Size of the application.   |
| cacheSize<sup>9+</sup> | number | Cache size of the application.  |
| dataSize<sup>9+</sup>  | number | Total data size of the application.|