提交 4a0504c6 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 809833a6
# User File Access and Management # User File Access and Management
>![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> >**NOTE**<br/>
> >
>- 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 initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>- The APIs of this module are system APIs and cannot be called by third-party applications. Currently, these APIs can be called only by **filepicker**. >- The APIs of this module are system APIs and cannot be called by third-party applications. Currently, these APIs can be called only by **filepicker**.
This module provides service APIs for accessing and managing user files. It interworks with the underlying file management services to implement media library and external card management, and provides capabilities for applications to query and create user files.
## Modules to Import ## Modules to Import
```js ```js
...@@ -81,8 +83,8 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -81,8 +83,8 @@ Obtains information about the second-level album or files in asynchronous mode.
- Parameters - Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| path | string | Yes| URI of the directory to query.| | path | promise<string>| Yes| URI of the directory to query.|
| type | string | Yes| Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.| | type | promise<string>| Yes| Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.| | options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.|
- Return value - Return value
...@@ -128,8 +130,8 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -128,8 +130,8 @@ Obtains information about the second-level album or files in asynchronous mode.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | URI of the directory to query. | | path | promise<string> | Yes | URI of the directory to query. |
| type | string | Yes | Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.| | type | promise<string> | Yes | Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.| | options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. |
- Error - Error
...@@ -156,7 +158,7 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -156,7 +158,7 @@ Obtains information about the second-level album or files in asynchronous mode.
## filemanager.createFile ## filemanager.createFile
filemanager.createFile(path : string, filename : string, options? : {dev? : DevInfo}) : Promise&lt;string&gt; createFile(path : string, filename : string, options? : {dev? : DevInfo}) : Promise&lt;string&gt;
Creates a file in the specified path in asynchronous mode. This API uses a promise to return the result. Creates a file in the specified path in asynchronous mode. This API uses a promise to return the result.
...@@ -165,8 +167,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a promi ...@@ -165,8 +167,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a promi
- Parameters - Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| filename | string | Yes| Name of the file to create.| | filename | promise<string>| Yes| Name of the file to create.|
| path | string | Yes| URI of the file to create.| | path | promise<string>| Yes| URI of the file to create.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.| | options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
- Return value - Return value
...@@ -209,8 +211,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a callb ...@@ -209,8 +211,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a callb
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| filename | string | Yes | Name of the file to create. | | filename | promise<string> | Yes | Name of the file to create. |
| path | string | Yes | URI of the file to create. | | path | promise<string> | Yes | URI of the file to create. |
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.| | options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. |
...@@ -246,9 +248,9 @@ Defines the file information returned by **getRoot()** or **listFile()**. ...@@ -246,9 +248,9 @@ Defines the file information returned by **getRoot()** or **listFile()**.
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| --- | -- | -- | -- | -- | | --- | -- | -- | -- | -- |
| name | string | Yes| No| File name.| | name | promise<string>| Yes| No| File name.|
| path | string | Yes| No| URI of the file.| | path | promise<string>| Yes| No| URI of the file.|
| type | string | Yes| No| File type.| | type | promise<string>| Yes| No| File type.|
| size | number | Yes| No| File size.| | size | number | Yes| No| File size.|
| addedTime | number | Yes| No| Time when the file was scanned to the database.| | addedTime | number | Yes| No| Time when the file was scanned to the database.|
| modifiedTime | number | Yes| No| Time when the file was modified.| | modifiedTime | number | Yes| No| Time when the file was modified.|
...@@ -263,4 +265,4 @@ Defines the device type. ...@@ -263,4 +265,4 @@ Defines the device type.
| Name| Type | Readable| Writable| Description | | Name| Type | Readable| Writable| Description |
| ------ | ------ | ---- | ---- | -------- | | ------ | ------ | ---- | ---- | -------- |
| name | string | Yes | Yes | Device name.| | name | promise<string>| Yes | Yes | Device name.|
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
> **NOTE**<br/> > **NOTE**<br/>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
This module provides functions related to file security levels. It provides JS APIs to obtain and set file security levels. The APIs of this module can be used to obtain and set file security levels.
## Modules to Import ## Modules to Import
...@@ -64,7 +64,7 @@ Sets the security label for a file in asynchronous mode. This API uses a promise ...@@ -64,7 +64,7 @@ Sets the security label for a file in asynchronous mode. This API uses a promise
setSecurityLabel(path:string, dataLevel:string, callback: AsyncCallback&lt;void&gt;):void setSecurityLabel(path:string, dataLevel:string, callback: AsyncCallback&lt;void&gt;):void
Sets the security label for a file in asynchronous mode. This API uses an asynchronous callback to return the result. Sets the security label for a file in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.DistributedFile **System capability**: SystemCapability.FileManagement.File.DistributedFile
...@@ -138,7 +138,7 @@ Obtains the security label of a file in asynchronous mode. This API uses a promi ...@@ -138,7 +138,7 @@ Obtains the security label of a file in asynchronous mode. This API uses a promi
getSecurityLabel(path:string, callback:AsyncCallback&lt;string&gt;): void getSecurityLabel(path:string, callback:AsyncCallback&lt;string&gt;): void
Obtains the security label of a file in asynchronous mode. This API uses an asynchronous callback to return the result. Obtains the security label of a file in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.DistributedFile **System capability**: SystemCapability.FileManagement.File.DistributedFile
......
# App Storage Statistics # App Storage Statistics
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br/>
> >
> - 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 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.
> - API version 9 is a canary release for trial use. The APIs of this version may be unstable. > - API version 9 is a canary version for trial use. The APIs of this version may be unstable.
The APIs of this module can be used to obtain 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.
## Modules to Import ## Modules to Import
...@@ -15,10 +17,14 @@ import storagestatistics from "@ohos.storageStatistics"; ...@@ -15,10 +17,14 @@ import storagestatistics from "@ohos.storageStatistics";
getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt; getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
Asynchronously obtains the total space of the specified volume. This API uses a promise to return the result. Asynchronously obtains the total size of the specified volume. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
**System API**: This is a system API and cannot be called by third-party applications.
- Parameters - Parameters
| Name | Type | Mandatory| Description| | Name | Type | Mandatory| Description|
...@@ -29,7 +35,7 @@ Asynchronously obtains the total space of the specified volume. This API uses a ...@@ -29,7 +35,7 @@ Asynchronously obtains the total space of the specified volume. This API uses a
| Type | Description | | Type | Description |
| --------------------- | ---------------- | | --------------------- | ---------------- |
| Promise&lt;number&gt; | Promise used to return the total space of the volume.| | Promise&lt;number&gt; | Promise used to return the total size of the volume.|
- Example - Example
...@@ -46,16 +52,20 @@ Asynchronously obtains the total space of the specified volume. This API uses a ...@@ -46,16 +52,20 @@ Asynchronously obtains the total space of the specified volume. This API uses a
getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void
Asynchronously obtains the total space of the specified volume. This API uses a callback to return the result. Asynchronously obtains the total size of the specified volume. This API uses a callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
**System API**: This is a system API and cannot be called by third-party applications.
- Parameters - Parameters
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | -------------------------- | | ---------- | ------------------------------------ | ---- | -------------------------- |
| volumeUuid | string | Yes | UUID of the volume. | | volumeUuid | string | Yes | UUID of the volume. |
| callback | callback:AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the total space of the volume.| | callback | callback:AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the total size of the volume.|
- Example - Example
...@@ -75,8 +85,12 @@ getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt; ...@@ -75,8 +85,12 @@ getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
Asynchronously obtains the available space of the specified volume. This API uses a promise to return the result. Asynchronously obtains the available space of the specified volume. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
**System API**: This is a system API and cannot be called by third-party applications.
- Parameters - Parameters
| Name | Type | Mandatory| Description| | Name | Type | Mandatory| Description|
...@@ -107,8 +121,12 @@ getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):vo ...@@ -107,8 +121,12 @@ getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):vo
Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result. Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
**System API**: This is a system API and cannot be called by third-party applications.
- Parameters - Parameters
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
...@@ -130,21 +148,25 @@ Asynchronously obtains the available space of the specified volume. This API use ...@@ -130,21 +148,25 @@ Asynchronously obtains the available space of the specified volume. This API use
getBundleStats(packageName: string): Promise&lt;BundleStats&gt; getBundleStats(packageName: string): Promise&lt;BundleStats&gt;
Asynchronously obtains app information. This API uses a promise to return the result. Asynchronously obtains information about an application. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
**System API**: This is a system API and cannot be called by third-party applications.
- Parameters - Parameters
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | -------- | | ----------- | ------ | ---- | -------- |
| packageName | string | Yes | Bundle name of the app.| | packageName | string | Yes | Bundle name of the application.|
- Return value - Return value
| Type | Description | | Type | Description |
| ------------------------------------------ | -------------------------- | | ------------------------------------------ | -------------------------- |
| Promise&lt;[Bundlestats](#bundlestats)&gt; | Promise used to return the app information.| | Promise&lt;[Bundlestats](#bundlestats)&gt; | Promise used to return the application information obtained.|
- Example - Example
...@@ -161,16 +183,20 @@ Asynchronously obtains app information. This API uses a promise to return the re ...@@ -161,16 +183,20 @@ Asynchronously obtains app information. This API uses a promise to return the re
getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;): void getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;): void
Asynchronously obtains app information. This API uses a callback to return the result. Asynchronously obtains information about an application. This API uses a callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
**System API**: This is a system API and cannot be called by third-party applications.
- Parameters - Parameters
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ | | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| packageName | string | Yes | Bundle name of the app.| | packageName | string | Yes | Bundle name of the application.|
| callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | Yes | Callback invoked to return the app information.| | callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | Yes | Callback invoked to return the application information obtained.|
- Example - Example
...@@ -182,14 +208,310 @@ Asynchronously obtains app information. This API uses a callback to return the r ...@@ -182,14 +208,310 @@ Asynchronously obtains app information. This API uses a callback to return the r
}); });
``` ```
## storagestatistics.getCurrentBundleStats<sup>9+</sup>
getCurrentBundleStats(): Promise<BundleStats>
Asynchronously obtains information about the current third-party application. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
- Return value
| Type | Description |
| ------------------------------------------ | -------------------------- |
| Promise&lt;[Bundlestats](#bundlestats)&gt; | Promise used to return the application information obtained. |
- Example
```js
let bundleStats = await storageStatistics.getCurrentBundleStats();
console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
```
## storagestatistics.getCurrentBundleStats<sup>9+</sup>
getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void
Asynchronously obtains information about the current third-party application. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
- Parameters
| Name | Type | Mandatory | Description |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| callback | callback:AsyncCallback&lt;[BundleStats](#bundlestats)&gt; | Yes | Callback invoked to return the application information obtained. |
- Example
```js
storagestatistics.getCurrentBundleStats(function(error, bundleStats){
// Do something.
console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
});
```
## BundleStats<sup>9+</sup> ## BundleStats<sup>9+</sup>
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
### Attributes - Attribute
| Name | Type | Description |
| --------- | ------ | -------------- |
| appSize | number | Size of the application. |
| cacheSize | number | Cache size of the application. |
| dataSize | number | Total data size of the application.|
## storagestatistics.getTotalSize<sup>9+</sup>
getTotalSize(): Promise<number>
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
**System API**: This is a system API and cannot be called by third-party applications.
- Return value
| Type | Description |
| --------------------- | ------------------ |
| Promise&lt;number&gt; | Promise used to return the total space of the built-in memory card. |
- Example
```js
let number = await storageStatistics.getTotalSize();
console.info("getTotalSize successfully:"+ JSON.stringify(number));
```
## storagestatistics.getTotalSize<sup>9+</sup>
getTotalSize(callback: AsyncCallback<number>): void
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
**System API**: This is a system API and cannot be called by third-party applications.
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ------------------------------------ | ---- | ------------------------ |
| callback | callback:AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the total space of the built-in memory card.|
- Example
```js
storagestatistics.getTotalSize(function(error, number){
// Do something.
console.info("getTotalSize successfully:"+ JSON.stringify(number));
});
```
## storagestatistics.getFreeSize<sup>9+</sup>
getFreeSize(): Promise<number>
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
**System API**: This is a system API and cannot be called by third-party applications.
- Return value
| Type | Description |
| --------------------- | ------------------ |
| Promise&lt;number&gt; | Promise used to return the available space of the built-in memory card.|
- Example
```js
let number = await storageStatistics.getFreeSize();
console.info("getFreeSize successfully:"+ JSON.stringify(number));
```
## storagestatistics.getFreeSize<sup>9+</sup>
getFreeSize(callback: AsyncCallback<number>): void
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
**System API**: This is a system API and cannot be called by third-party applications.
- Parameters
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | ------------------------- |
| callback | callback:AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the available space of the built-in memory card.|
- Example
```js
storagestatistics.getFreeSize(function(error, number){
// Do something.
console.info("getFreeSize successfully:"+ JSON.stringify(number));
});
```
## storagestatistics.getSystemSize<sup>9+</sup>
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
**System API**: This is a system API and cannot be called by third-party applications.
- Return value
| Type | Description |
| --------------------- | ---------------- |
| Promise&lt;number&gt; | Promise used to return the system space obtained.|
- Example
```js
storagestatistics.getSystemSize().then(function(number){
console.info("getSystemSize successfully:"+ number);
}).catch(function(err){
console.info("getSystemSize failed with error:"+ err);
});
```
## storagestatistics.getSystemSize<sup>9+</sup>
getSystemSize(callback:AsyncCallback&lt;number&gt;):void
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
**System API**: This is a system API and cannot be called by third-party applications.
- Parameters
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| callback | callback:AsyncCallback&lt;number&gt; | Yes | Callback used to return the system space obtained.|
- Example
```js
storagestatistics.getSystemSize(function(error, number){
// Do something.
console.info("getSystemSize successfully:"+ number);
});
```
## storagestatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId?: string): Promise&lt;StorageStats&gt;
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
**System API**: This is a system API and cannot be called by third-party applications.
- Parameters
| Name | Type | Mandatory| Description|
| ---------- | ------ | ---- | ---- |
| userId | string | 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.|
- Return value
| Type | Description |
| --------------------- | ---------------- |
| Promise&lt;[StorageStats](#StorageStats)&gt; | Promise used to return the information obtained.|
- Example
```js
let userId = "";
storagestatistics.getUserStorageStats(userId).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(userId?: string, callback:AsyncCallback&lt;StorageStats&gt;):void
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
**System API**: This is a system API and cannot be called by third-party applications.
- Parameters
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| userId | string | 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. |
| callback | callback:AsyncCallback&lt;[StorageStats](#StorageStats)&gt; | Yes | Callback invoked to return the information obtained.|
- Example
```js
storagestatistics.getUserStorageStats(userId, function(error, StorageStats){
// Do something.
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
});
```
## StorageStats<sup>9+</sup>
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
- Attribute
| Name | Type | Description | | Name | Type | Description |
| --------- | ------ | -------------- | | --------- | ------ | -------------- |
| appSize<sup>9+</sup> | number | Size of the app. | | total | number | Total space of the built-in memory card. |
| cacheSize<sup>9+</sup> | number | Cache size of the app. | | audio | number | Space occupied by the audio data. |
| dataSize<sup>9+</sup> | number | Total data size of the app.| | video | number | Space occupied by the video data.|
| image | number | Space occupied by the image data. |
| file | number | Space occupied by files. |
| app | number | Space occupied by the application data.|
# Volume Management # Volume Management
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br>
> >
> - The initial APIs of this module are supported since API version 9. > - The initial APIs of this module are supported since API version 9.
> - API version 9 is a canary release for trial use. The APIs of this version may be unstable. > - 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.
The APIs of this module can be used to perform volume and disk management, including obtaining volume information, mounting and unmounting volumes, partitioning disks, and formatting volumes.
## Modules to Import ## Modules to Import
...@@ -15,7 +18,7 @@ import volumemanager from "@ohos.volumeManager"; ...@@ -15,7 +18,7 @@ import volumemanager from "@ohos.volumeManager";
getAllVolumes(): Promise&lt;Array&lt;Volume&gt;&gt; getAllVolumes(): Promise&lt;Array&lt;Volume&gt;&gt;
Asynchronously obtains information about all available volumes. This method uses a promise to return the result. Asynchronously obtains information about all available volumes. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
...@@ -37,7 +40,7 @@ Asynchronously obtains information about all available volumes. This method uses ...@@ -37,7 +40,7 @@ Asynchronously obtains information about all available volumes. This method uses
getAllVolumes(callback: AsyncCallback&lt;Array&lt;Volume&gt;&gt;): void getAllVolumes(callback: AsyncCallback&lt;Array&lt;Volume&gt;&gt;): void
Asynchronously obtains information about all available volumes. This method uses a callback to return the result. Asynchronously obtains information about all available volumes. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
...@@ -61,7 +64,7 @@ Asynchronously obtains information about all available volumes. This method uses ...@@ -61,7 +64,7 @@ Asynchronously obtains information about all available volumes. This method uses
mount(volumeId: string): Promise&lt;boolean&gt; mount(volumeId: string): Promise&lt;boolean&gt;
Asynchronously mounts a volume. This method uses a promise to return the result. Asynchronously mounts a volume. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
...@@ -90,7 +93,7 @@ Asynchronously mounts a volume. This method uses a promise to return the result. ...@@ -90,7 +93,7 @@ Asynchronously mounts a volume. This method uses a promise to return the result.
mount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void mount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void
Asynchronously obtains the available space of the specified volume. This method uses a callback to return the result. Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
...@@ -114,7 +117,7 @@ Asynchronously obtains the available space of the specified volume. This method ...@@ -114,7 +117,7 @@ Asynchronously obtains the available space of the specified volume. This method
unmount(volumeId: string): Promise&lt;boolean&gt; unmount(volumeId: string): Promise&lt;boolean&gt;
Asynchronously unmounts a volume. This method uses a promise to return the result. Asynchronously unmounts a volume. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
...@@ -143,7 +146,7 @@ Asynchronously unmounts a volume. This method uses a promise to return the resul ...@@ -143,7 +146,7 @@ Asynchronously unmounts a volume. This method uses a promise to return the resul
unmount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void unmount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void
Asynchronously unmounts a volume. This method uses a callback to return the result. Asynchronously unmounts a volume. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册