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_wang 已提交
6
> - API version 9 is a canary release for trial use. The APIs of this version may be unstable.
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
```

## storagestatistics.getTotalSizeOfVolume

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

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

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
  | --------------------- | ---------------- |
  | 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 已提交
49
Asynchronously obtains the total space of the specified volume. This API uses a callback to return the result.
A
annie_wangli 已提交
50

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

- Example

  ```js
  let uuid = "";
  storagestatistics.getTotalSizeOfVolume(uuid, function(error, number){
A
Annie_wang 已提交
65
      // 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
  

## storagestatistics.getFreeSizeOfVolume

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

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

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
  | --------------------- | ------------------ |
  | 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 已提交
108
Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result.
A
annie_wangli 已提交
109

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

- Example

  ```js
  let uuid = "";
  storagestatistics.getFreeSizeOfVolume(uuid, function(error, number){
A
Annie_wang 已提交
124
      // Do something.
A
annie_wangli 已提交
125
      console.info("getFreeSizeOfVolume successfully:"+ number);
A
annie_wangli 已提交
126 127
  });
  ```
A
Annie_wang 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195

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

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

Asynchronously obtains app information. This API uses a promise to return the result.

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

- Parameters

  | Name     | Type  | Mandatory| Description    |
  | ----------- | ------ | ---- | -------- |
  | packageName | string | Yes  | Bundle name of the app.|
  
- Return value

  | Type                                      | Description                      |
  | ------------------------------------------ | -------------------------- |
  | Promise&lt;[Bundlestats](#bundlestats)&gt; | Promise used to return the app information.|

- 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

Asynchronously obtains app information. This API uses a callback to return the result.

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

- Parameters

  | 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 app information.|
  
- 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

### Attributes

| Name     | Type  | Description          |
| --------- | ------ | -------------- |
| appSize<sup>9+</sup>   | number | Size of the app.   |
| cacheSize<sup>9+</sup> | number | Cache size of the app.  |
| dataSize<sup>9+</sup>  | number | Total data size of the app.|