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

A
annie_wangli 已提交
3
> ![icon-note.gif](public_sys-resources/icon-note.gif) **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_wangli 已提交
6
> - The APIs of this module are system APIs and cannot be called by third-party applications.
A
annie_wangli 已提交
7 8 9 10

## Modules to Import

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

## storagestatistics.getTotalSizeOfVolume

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

Asynchronously obtains the total space of the specified volume. This method uses a promise to return the result.

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

A
annie_wangli 已提交
22 23
- Parameters

A
annie_wangli 已提交
24
  | Name    | Type  | Mandatory| Description|
A
annie_wangli 已提交
25
  | ---------- | ------ | ---- | ---- |
A
annie_wangli 已提交
26
  | volumeUuid | string | Yes  | UUID of the volume.|
A
annie_wangli 已提交
27 28 29

- Return value

A
annie_wangli 已提交
30
  | Type                 | Description            |
A
annie_wangli 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  | --------------------- | ---------------- |
  | 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

Asynchronously obtains the total space of the specified volume. This method uses a callback to return the result.

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

A
annie_wangli 已提交
53 54
- Parameters

A
annie_wangli 已提交
55
  | Name    | Type                                | Mandatory| Description                      |
A
annie_wangli 已提交
56
  | ---------- | ------------------------------------ | ---- | -------------------------- |
A
annie_wangli 已提交
57 58
  | 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 已提交
59 60 61 62 63 64 65

- Example

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

## storagestatistics.getFreeSizeOfVolume

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

Asynchronously obtains the available space of the specified volume. This method uses a promise to return the result.

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

A
annie_wangli 已提交
80 81
- Parameters

A
annie_wangli 已提交
82
  | Name    | Type  | Mandatory| Description|
A
annie_wangli 已提交
83
  | ---------- | ------ | ---- | ---- |
A
annie_wangli 已提交
84
  | volumeUuid | string | Yes  | UUID of the volume.|
A
annie_wangli 已提交
85 86 87

- Return value

A
annie_wangli 已提交
88
  | Type                 | Description              |
A
annie_wangli 已提交
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
  | --------------------- | ------------------ |
  | 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

Asynchronously obtains the available space of the specified volume. This method uses a callback to return the result.

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

A
annie_wangli 已提交
112 113
- Parameters

A
annie_wangli 已提交
114
  | Name    | Type                                | Mandatory| Description                        |
A
annie_wangli 已提交
115
  | ---------- | ------------------------------------ | ---- | ---------------------------- |
A
annie_wangli 已提交
116 117
  | 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 已提交
118 119 120 121 122 123 124

- Example

  ```js
  let uuid = "";
  storagestatistics.getFreeSizeOfVolume(uuid, function(error, number){
      // Do something
A
annie_wangli 已提交
125
      console.info("getFreeSizeOfVolume successfully:"+ number);
A
annie_wangli 已提交
126 127 128
  });
  ```

A
annie_wangli 已提交
129
## storagestatistics.getBundleStats<sup>9+</sup>
A
annie_wangli 已提交
130

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

A
annie_wangli 已提交
133 134 135
Obtains the bundle status. This method uses a promise to return the result.

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
A
annie_wangli 已提交
136 137 138

- Parameters

A
annie_wangli 已提交
139
  | Name     | Type  | Mandatory| Description    |
A
annie_wangli 已提交
140
  | ----------- | ------ | ---- | -------- |
A
annie_wangli 已提交
141 142
  | packageName | string | Yes  | Bundle name of the app.|
  
A
annie_wangli 已提交
143 144
- Return value

A
annie_wangli 已提交
145
  | Type                                      | Description                      |
A
annie_wangli 已提交
146 147 148 149 150 151 152
  | ------------------------------------------ | -------------------------- |
  | Promise&lt;[Bundlestats](#bundlestats)&gt; | Promise used to return the bundle status on the volume.|

- Example

  ```js
  let packageName = "";
A
annie_wangli 已提交
153
  storagestatistics.getBundleStats(packageName).then(function(BundleStats){
A
annie_wangli 已提交
154 155 156 157 158 159
      console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
  }).catch(function(err){
      console.info("getBundleStats failed with error:"+ err);
  });
  ```

A
annie_wangli 已提交
160
## storagestatistics.getBundleStats<sup>9+</sup>
A
annie_wangli 已提交
161

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

A
annie_wangli 已提交
164
Obtains the bundle status. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
165

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

A
annie_wangli 已提交
168
- Parameters
A
annie_wangli 已提交
169

A
annie_wangli 已提交
170 171 172 173 174
  | Name  | Type                                                     | Mandatory| Description                                |
  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
  | packageName | string | Yes  | Bundle name of the app.|
  | callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | Yes  | Callback invoked to return the bundle status on the volume.|
  
A
annie_wangli 已提交
175 176 177 178
- Example

  ```js
  let packageName = "";
A
annie_wangli 已提交
179
  storagestatistics.getBundleStats(packageName, function(error, BundleStats){
A
annie_wangli 已提交
180
      // Do something
A
annie_wangli 已提交
181
      console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
A
annie_wangli 已提交
182 183 184
  });
  ```

A
annie_wangli 已提交
185 186 187
## BundleStats<sup>9+</sup>

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
A
annie_wangli 已提交
188 189 190

### Attributes

A
annie_wangli 已提交
191
| Name     | Type  | Description          |
A
annie_wangli 已提交
192
| --------- | ------ | -------------- |
A
annie_wangli 已提交
193 194 195
| appSize<sup>9+</sup>   | number | Size of the app.   |
| cacheSize<sup>9+</sup> | number | Size of the cached data.  |
| dataSize<sup>9+</sup>  | number | Total data size of the app.|