提交 006b1f59 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 20cdc2b1
......@@ -224,8 +224,8 @@
- [@ohos.file.statvfs (File System Space Statistics)](js-apis-file-statvfs.md)
- [@ohos.filemanagement.userFileManager (User Data Management)](js-apis-userFileManager.md)
- [@ohos.multimedia.medialibrary (Media Library Management)](js-apis-medialibrary.md)
- [@ohos.storageStatistics (Application Storage Statistics)](js-apis-storage-statistics.md)
- [@ohos.volumeManager (Volume Management)](js-apis-volumemanager.md)
- [@ohos.file.storageStatistics (Application Storage Statistics)](js-apis-file-storage-statistics.md)
- [@ohos.file.volumeManager (Volume Management)](js-apis-file-volumemanager.md)
- Telephony Service
- [@ohos.contact (Contacts)](js-apis-contact.md)
- [@ohos.telephony.call (Call)](js-apis-call.md)
......
......@@ -198,18 +198,23 @@ Creates an app account implicitly based on the specified account owner. This API
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, result) {
console.log("resultCode: " + code);
console.log("result: " + JSON.stringify(result));
}
function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request};
featureAbility.startAbility(abilityStartSetting, (err) => {
let wantInfo = {
deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.log("startAbility successfully");
}).catch((err) => {
console.log("startAbility err: " + JSON.stringify(err));
});
})
}
try {
......@@ -252,18 +257,23 @@ Creates an app account implicitly based on the specified account owner and optio
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, result) {
console.log("resultCode: " + code);
console.log("result: " + JSON.stringify(result));
}
function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request};
featureAbility.startAbility(abilityStartSetting, (err) => {
let wantInfo = {
deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.log("startAbility successfully");
}).catch((err) => {
console.log("startAbility err: " + JSON.stringify(err));
});
})
}
let options = {
......@@ -1090,7 +1100,8 @@ getAllAccounts(callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
Obtains information about all accessible app accounts. This API uses an asynchronous callback to return the result.
**Required Permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS
**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS
**System capability**: SystemCapability.Account.AppAccount
**Parameters**
......@@ -1127,7 +1138,8 @@ getAllAccounts(): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;
Obtains information about all accessible app accounts. This API uses a promise to return the result.
**Required Permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS
**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS
**System capability**: SystemCapability.Account.AppAccount
**Return value**
......@@ -1162,7 +1174,8 @@ getAccountsByOwner(owner: string, callback: AsyncCallback&lt;Array&lt;AppAccount
Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses an asynchronous callback to return the result.
**Required Permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS
**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS
**System capability**: SystemCapability.Account.AppAccount
**Parameters**
......@@ -1202,7 +1215,8 @@ getAccountsByOwner(owner: string): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;
Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses a promise to return the result.
**Required Permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS
**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS
**System capability**: SystemCapability.Account.AppAccount
**Parameters**
......@@ -1303,7 +1317,7 @@ Unsubscribes from account information changes.
**Example**
```js
function changeOnCallback(data) {
function changeOnCallback(data){
console.log("receive change data:" + JSON.stringify(data));
}
try{
......@@ -1350,7 +1364,7 @@ Authenticates an app account. This API uses an asynchronous callback to return t
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, authResult) {
console.log("resultCode: " + code);
......@@ -1358,10 +1372,17 @@ Authenticates an app account. This API uses an asynchronous callback to return t
}
function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request};
featureAbility.startAbility(abilityStartSetting, (err) => {
console.log("startAbility err: " + JSON.stringify(err));
});
let wantInfo = {
deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.log("startAbility successfully");
}).catch((err) => {
console.log("startAbility err: " + JSON.stringify(err));
})
}
try {
......@@ -1406,7 +1427,7 @@ Authenticates an app account with customized options. This API uses an asynchron
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, authResult) {
console.log("resultCode: " + code);
......@@ -1414,10 +1435,17 @@ Authenticates an app account with customized options. This API uses an asynchron
}
function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request};
featureAbility.startAbility(abilityStartSetting, (err) => {
console.log("startAbility err: " + JSON.stringify(err));
});
let wantInfo = {
deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.log("startAbility successfully");
}).catch((err) => {
console.log("startAbility err: " + JSON.stringify(err));
})
}
let options = {
......@@ -2710,7 +2738,7 @@ Adds an app account. This API uses an asynchronous callback to return the result
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | -------------------- |
| name | string | Yes | Name of the target app account. |
| name | string | Yes | Name of the app account to add. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Example**
......@@ -2755,8 +2783,7 @@ addAccount(name: string, extraInfo?: string): Promise&lt;void&gt;
Adds an app account name and additional information. This API uses an asynchronous callback to return the result. This API uses a promise to return the result.
> **NOTE**
>
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createAccount](#createaccount9-2).
**System capability**: SystemCapability.Account.AppAccount
......@@ -2808,7 +2835,7 @@ Adds an app account implicitly based on the specified owner. This API uses an as
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, result) {
console.log("resultCode: " + code);
......@@ -2816,10 +2843,17 @@ Adds an app account implicitly based on the specified owner. This API uses an as
}
function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request};
featureAbility.startAbility(abilityStartSetting, (err)=>{
let wantInfo = {
deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.log("startAbility successfully");
}).catch((err) => {
console.log("startAbility err: " + JSON.stringify(err));
});
})
}
appAccountManager.addAccountImplicitly("com.example.accountjsdemo", "getSocialData", {}, {
......@@ -2844,7 +2878,7 @@ Deletes an app account. This API uses an asynchronous callback to return the res
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------- |
| name | string | Yes | Name of the target app account. |
| name | string | Yes | Name of the app account to delete. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Example**
......@@ -2871,7 +2905,7 @@ Deletes an app account. This API uses a promise to return the result.
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| name | string | Yes | Name of the target app account.|
| name | string | Yes | Name of the app account to delete.|
**Return value**
......@@ -3756,18 +3790,23 @@ Authenticates an app account with customized options. This API uses an asynchron
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, result) {
console.log("resultCode: " + code);
console.log("result: " + JSON.stringify(result));
}
function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request};
featureAbility.startAbility(abilityStartSetting, (err)=>{
console.log("startAbility err: " + JSON.stringify(err));
});
let wantInfo = {
deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.log("startAbility successfully");
}).catch((err) => {
console.log("startAbility err: " + JSON.stringify(err));
})
}
appAccountManager.authenticate("LiSi", "com.example.accountjsdemo", "getSocialData", {}, {
......@@ -4526,10 +4565,13 @@ Enumerates the constants.
| KEY_REQUIRED_LABELS<sup>9+</sup> | "requiredLabels" | Required labels. |
| KEY_BOOLEAN_RESULT<sup>9+</sup> | "booleanResult" | Return value of the Boolean type. |
## ResultCode<sup>8+</sup>
## ResultCode<sup>(deprecated)</sup>
Enumerates the result codes.
> **NOTE**
> This enum is supported since API version 8 and deprecated since API version 9. From API version 9, error codes are used. For details about the error codes, see [App Account Error Codes](../errorcodes/errorcode-account.md).
**System capability**: SystemCapability.Account.AppAccount
| Name | Value | Description |
......@@ -4765,7 +4807,7 @@ Creates an app account implicitly based on the specified account owner. This API
| Name | Type | Mandatory | Description |
| ---------------- | --------------------- | ---- | --------------- |
| options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | Yes | Options for implicitly creating the account. |
| options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | Yes | Options for implicitly creating an account. |
| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the result.|
### addAccountImplicitly<sup>(deprecated)</sup>
......
......@@ -15,7 +15,7 @@ import fs from '@ohos.file.fs';
## Guidelines
Before using the APIs provided by this module to perform operations on files or directories, obtain the path of the application sandbox as follows:
Before using the APIs provided by this module to perform operations on files or directories, obtain the path of the file or directory in the application sandbox as follows:
**Stage Model**
......@@ -147,7 +147,7 @@ Checks whether a file exists. This API uses a promise to return the result.
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;boolean&gt; | Promise used to return a Boolean value. |
| Promise&lt;boolean&gt; | Promise used to return a Boolean value.|
**Example**
......@@ -1079,7 +1079,7 @@ Reads the text content of a file. This API uses an asynchronous callback to retu
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Path of the file in the application sandbox. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the file length.<br>- **encoding** (string): format of the string to be encoded. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the content read. |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the content read. |
**Example**
......@@ -1169,7 +1169,7 @@ Obtains information about a symbolic link. This API uses an asynchronous callbac
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | -------------------------------------- |
| path | string | Yes | Path of the symbolic link in the application sandbox.|
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback used to return the symbolic link information obtained. |
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the symbolic link information obtained. |
**Example**
......@@ -1215,7 +1215,7 @@ Obtains information about a symbolic link synchronously.
rename(oldPath: string, newPath: string): Promise&lt;void&gt;
Renames a file. This API uses a promise to return the result.
Renames a file or directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1248,7 +1248,7 @@ Renames a file. This API uses a promise to return the result.
rename(oldPath: string, newPath: string, callback: AsyncCallback&lt;void&gt;): void
Renames a file. This API uses an asynchronous callback to return the result.
Renames a file or directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1278,7 +1278,7 @@ Renames a file. This API uses an asynchronous callback to return the result.
renameSync(oldPath: string, newPath: string): void
Synchronously renames a file.
Renames a file or directory synchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1366,7 +1366,7 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
fsyncSync(fd: number): void
Flushes data of a file to disk in synchronous mode.
Flushes data of a file to disk synchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1454,7 +1454,7 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
fdatasyncSync(fd: number): void
Synchronizes data in a file in synchronous mode.
Synchronizes data in a file synchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......
......@@ -36,14 +36,14 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
```js
let path = "/dev";
statfs.getFreeSize(path).then((number) => {
statvfs.getFreeSize(path).then((number) => {
console.info("getFreeSize promise successfully, Size: " + number);
}).catch((err) => {
console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code);
});
```
## statfs.getFreeSize
## statvfs.getFreeSize
getFreeSize(path:string, callback:AsyncCallback&lt;number&gt;): void
......@@ -62,7 +62,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
```js
let path = "/dev";
statfs.getFreeSize(path, (err, number) => {
statvfs.getFreeSize(path, (err, number) => {
if (err) {
console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code);
} else {
......@@ -71,7 +71,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
});
```
## statfs.getTotalSize
## statvfs.getTotalSize
getTotalSize(path: string): Promise&lt;number&gt;
......@@ -95,14 +95,14 @@ Obtains the total number of bytes of the specified file system in asynchronous m
```js
let path = "/dev";
statfs.getTotalSize(path).then((number) => {
statvfs.getTotalSize(path).then((number) => {
console.info("getTotalSize promise successfully, Size: " + number);
}).catch((err) => {
console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code);
});
```
## statfs.getTotalSize
## statvfs.getTotalSize
getTotalSize(path: string, callback: AsyncCallback&lt;number&gt;): void
......@@ -121,7 +121,7 @@ Obtains the total number of bytes of the specified file system in asynchronous m
```js
let path = "/dev";
statfs.getTotalSize(path, (err, number) => {
statvfs.getTotalSize(path, (err, number) => {
if (err) {
console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code);
} else {
......
# @ohos.file.storageStatistics (Application Storage Statistics)
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.
> **NOTE**
>
> - 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 APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
## Modules to Import
```js
import storageStatistics from "@ohos.file.storageStatistics";
```
## storageStatistics.getTotalSizeOfVolume
getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
Obtains the total size (in bytes) of the specified volume in an external storage device. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description|
| ---------- | ------ | ---- | ---- |
| volumeUuid | string | Yes | UUID of the volume.|
**Return value**
| Type | Description |
| --------------------- | ---------------- |
| Promise&lt;number&gt; | Promise used to return the total volume size obtained.|
**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
Obtains the total size (in bytes) of the specified volume in an external storage device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| volumeUuid | string | Yes | UUID of the volume. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the total volume size obtained.|
**Example**
```js
let uuid = "";
storageStatistics.getTotalSizeOfVolume(uuid, function(error, number){
// Do something.
console.info("getTotalSizeOfVolume successfully:"+ number);
});
```
## storageStatistics.getFreeSizeOfVolume
getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
Obtains the available space (in bytes) of the specified volume in an external storage device. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description|
| ---------- | ------ | ---- | ---- |
| volumeUuid | string | Yes | UUID of the volume.|
**Return value**
| Type | Description |
| --------------------- | ------------------ |
| Promise&lt;number&gt; | Promise used to return the available volume space obtained.|
**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
Obtains the available space (in bytes) of the specified volume in an external storage device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | ---------------------------- |
| volumeUuid | string | Yes | UUID of the volume. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the available volume space obtained.|
**Example**
```js
let uuid = "";
storageStatistics.getFreeSizeOfVolume(uuid, function(error, number){
// Do something.
console.info("getFreeSizeOfVolume successfully:"+ number);
});
```
## storageStatistics.getBundleStats<sup>9+</sup>
getBundleStats(packageName: string): Promise&lt;BundleStats&gt;
Obtains the space (in bytes) of an application. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | -------- |
| packageName | string | Yes | Bundle name of the application.|
**Return value**
| Type | Description |
| ------------------------------------------ | -------------------------- |
| Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise used to return the application space obtained.|
**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
Obtains the space (in bytes) of an application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| packageName | string | Yes | Bundle name of the application.|
| callback | AsyncCallback&lt;[Bundlestats](#bundlestats9)&gt; | Yes | Callback invoked to return the application space obtained.|
**Example**
```js
let packageName = "";
storageStatistics.getBundleStats(packageName, function(error, BundleStats){
// Do something.
console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
});
```
## storageStatistics.getCurrentBundleStats<sup>9+</sup>
getCurrentBundleStats(): Promise&lt;BundleStats&gt;
Obtains the space (in bytes) of this 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](#bundlestats9)&gt; | Promise used to return the application space obtained. |
**Example**
```js
let bundleStats = storageStatistics.getCurrentBundleStats();
console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
```
## storageStatistics.getCurrentBundleStats<sup>9+</sup>
getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void
Obtains the space (in bytes) of this third-party application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback&lt;[BundleStats](#bundlestats9)&gt; | Yes | Callback invoked to return the application space obtained. |
**Example**
```js
storageStatistics.getCurrentBundleStats(function(error, bundleStats){
// Do something.
console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
});
```
## BundleStats<sup>9+</sup>
### Attributes
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
| Name | Type | Readable| Writable| Description |
| --------- | ------ | --- | ---- | -------------- |
| appSize | number | Yes| No| Size of the application, in bytes. |
| cacheSize | number | Yes| No| Cache size of the application, in bytes. |
| dataSize | number | Yes| No| Total data size of the application, in bytes.|
## storageStatistics.getTotalSize<sup>9+</sup>
getTotalSize(): Promise&lt;number&gt;
Obtains the total size (in bytes) of the built-in storage. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Return value**
| Type | Description |
| --------------------- | ------------------ |
| Promise&lt;number&gt; | Promise used to return the built-in storage size obtained. |
**Example**
```js
let number = storageStatistics.getTotalSize();
console.info("getTotalSize successfully:"+ JSON.stringify(number));
```
## storageStatistics.getTotalSize<sup>9+</sup>
getTotalSize(callback: AsyncCallback&lt;number&gt;): void
Obtains the total size (in bytes) of the built-in storage. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------------ | ---- | ------------------------ |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the built-in storage size obtained.|
**Example**
```js
storageStatistics.getTotalSize(function(error, number){
// Do something.
console.info("getTotalSize successfully:"+ JSON.stringify(number));
});
```
## storageStatistics.getFreeSize<sup>9+</sup>
getFreeSize(): Promise&lt;number&gt;
Obtains the available space (in bytes) of the built-in storage. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Return value**
| Type | Description |
| --------------------- | ------------------ |
| Promise&lt;number&gt; | Promise used to return the available space of the built-in storage obtained.|
**Example**
```js
let number = storageStatistics.getFreeSize();
console.info("getFreeSize successfully:"+ JSON.stringify(number));
```
## storageStatistics.getFreeSize<sup>9+</sup>
getFreeSize(callback: AsyncCallback&lt;number&gt;): void
Obtains the available space (in bytes) of the built-in storage. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | ------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the available space of the built-in storage obtained.|
**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;
Obtains the system data space, in bytes. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Return value**
| Type | Description |
| --------------------- | ---------------- |
| Promise&lt;number&gt; | Promise used to return the system data 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
Obtains the system data space, in bytes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the system data space obtained.|
**Example**
```js
storageStatistics.getSystemSize(function(error, number){
// Do something.
console.info("getSystemSize successfully:"+ number);
});
```
## storageStatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(): Promise&lt;StorageStats&gt;
Obtains the storage statistics (in bytes) of this user. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Return value**
| Type | Description |
| --------------------- | ---------------- |
| Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the information obtained.|
**Example**
```js
storageStatistics.getUserStorageStats().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(callback: AsyncCallback&lt;StorageStats&gt;): void
Obtains the storage statistics (in bytes) of this user. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| callback | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes | Callback invoked to return the information obtained.|
**Example**
```js
storageStatistics.getUserStorageStats(function(error, StorageStats){
// Do something.
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
});
```
getUserStorageStats(userId: number): Promise&lt;StorageStats&gt;
Obtains the storage statistics (in bytes) of the specified user. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description|
| ---------- | ------ | ---- | ---- |
| userId | number | Yes | User ID.|
**Return value**
| Type | Description |
| --------------------- | ---------------- |
| Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the information obtained.|
**Example**
```js
let userId = 100;
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: number, callback: AsyncCallback&lt;StorageStats&gt;): void
Obtains the storage statistics (in bytes) of the specified user. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| userId | number | Yes | User ID.|
| callback | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes | Callback invoked to return the information obtained.|
**Example**
```js
let userId = 100;
storageStatistics.getUserStorageStats(userId, function(error, StorageStats){
// Do something.
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
});
```
## StorageStats<sup>9+</sup>
### Attributes
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
| Name | Type | Readable | Writable | Description |
| --------- | ------ | ---- | ----- | -------------- |
| total | number | Yes| No| Total size of the built-in storage, in bytes. |
| audio | number |Yes| No| Space occupied by audio data, in bytes. |
| video | number | Yes| No| Space occupied by video data, in bytes.|
| image | number | Yes| No| Space occupied by image data, in bytes. |
| file | number | Yes| No| Space occupied by files, in bytes. |
| app | number | Yes| No| Space occupied by application data, in bytes.|
# @ohos.file.volumeManager (Volument Management)
The volumeManager module provides APIs for volume and disk management, including obtaining volume information, mounting or unmounting volumes, partitioning disks, and formatting volumes.
> **NOTE**
>
> - 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 provided by this module are system APIs.
> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
## Modules to Import
```js
import volumemanager from "@ohos.file.volumeManager";
```
## volumemanager.getAllVolumes
getAllVolumes(): Promise&lt;Array&lt;Volume&gt;&gt;
Asynchronously obtains information about all available volumes. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Return value**
| Type | Description |
| ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)[]&gt; | Promise used to return the execution result.|
**Example**
```js
volumemanager.getAllVolumes().then(function(volumes){
// Do something.
});
```
## volumemanager.getAllVolumes
getAllVolumes(callback: AsyncCallback&lt;Array&lt;Volume&gt;&gt;): void
Asynchronously obtains information about all available volumes. This API uses a callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback&lt;[Volume](#volume)[]&gt; | Yes | Callback invoked to return the volume information obtained.|
**Example**
```js
let uuid = "";
volumemanager.getAllVolumes(function(error, volumes){
// Do something
});
```
## volumemanager.mount
mount(volumeId: string): Promise&lt;void&gt;
Asynchronously mounts a volume. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MOUNT_UNMOUNT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | ------ | ---- | ---- |
| volumeId | string | Yes | Volume ID.|
**Return value**
| Type | Description |
| ---------------------- | ---------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
let volumeId = "";
volumemanager.mount(volumeId).then(function(flag){
// Do something
});
```
## volumemanager.mount
mount(volumeId: string, callback:AsyncCallback&lt;void&gt;):void
Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MOUNT_UNMOUNT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------- |
| volumeId | string | Yes | Volume ID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Example**
```js
let volumeId = "";
volumemanager.mount(volumeId, function(error, flag){
// Do something
});
```
## volumemanager.unmount
unmount(volumeId: string): Promise&lt;void&gt;
Asynchronously unmounts a volume. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MOUNT_UNMOUNT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | ------ | ---- | ---- |
| volumeId | string | Yes | Volume ID.|
**Return value**
| Type | Description |
| ---------------------- | ---------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
let volumeId = "";
volumemanager.unmount(volumeId).then(function(flag){
// Do something
});
```
## volumemanager.unmount
unmount(volumeId: string, callback: AsyncCallback&lt;void&gt;): void
Asynchronously unmounts a volume. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MOUNT_UNMOUNT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------- |
| volumeId | string | Yes | Volume ID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Example**
```js
let volumeId = "";
volumemanager.unmount(volumeId, function(error, flag){
// Do something
});
```
## volumemanager.getVolumeByUuid
getVolumeByUuid(uuid: string): Promise&lt;Volume&gt;
Asynchronously obtains volume information based on the universally unique identifier (UUID). This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | ------ | ---- | ---- |
| uuid | string | Yes | UUID of the volume.|
**Return value**
| Type | Description |
| ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)&gt; | Promise used to return the volume information obtained.|
**Example**
```js
let uuid = "";
volumemanager.getVolumeByUuid(uuid).then(function(volume) {
console.info("getVolumeByUuid successfully:" + JSON.stringify(volume));
}).catch(function(error){
console.info("getVolumeByUuid failed with error:"+ error);
});
```
## volumemanager.getVolumeByUuid
getVolumeByUuid(uuid: string, callback: AsyncCallback&lt;Volume&gt;): void
Asynchronously obtains volume information based on the UUID. This API uses a callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------ | ---- | -------------------- |
| uuid | string | Yes | UUID of the volume. |
| callback | AsyncCallback&lt;[Volume](#volume)&gt; | Yes | Callback invoked to return the volume information obtained.|
**Example**
```js
let uuid = "";
volumemanager.getVolumeByUuid(uuid, (error, volume) => {
// Do something.
});
```
## volumemanager.getVolumeById
getVolumeById(volumeId: string): Promise&lt;Volume&gt;
Asynchronously obtains volume information based on the volume ID. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory | Description|
| -------- | ------ | ---- | ---- |
| volumeId | string | Yes | Volume ID.|
**Return value**
| Type | Description |
| ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)&gt; | Promise used to return the volume information obtained.|
**Example**
```js
let volumeId = "";
volumemanager.getVolumeById(volumeId).then(function(volume) {
console.info("getVolumeById successfully:" + JSON.stringify(volume));
}).catch(function(error){
console.info("getVolumeById failed with error:"+ error);
});
```
## volumemanager.getVolumeById
getVolumeById(volumeId: string, callback: AsyncCallback&lt;Volume&gt;): void
Asynchronously obtains volume information based on the volume ID. This API uses a callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- |
| volumeId | string | Yes | Volume ID. |
| callback | AsyncCallback&lt;[Volume](#volume)&gt; | Yes | Callback invoked to return the volume information obtained. |
**Example**
```js
let volumeId = "";
volumemanager.getVolumeById(volumeId, (error, volume) => {
// Do something.
});
```
## volumemanager.setVolumeDescription
setVolumeDescription(uuid: string, description: string): Promise&lt;void&gt;
Asynchronously sets the volume description based on the UUID. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MOUNT_UNMOUNT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description|
| --------- | ------ | ---- | ---- |
| uuid | string | Yes | UUID of the volume.|
| description | string | Yes | Volume description.|
**Return value**
| Type | Description |
| ---------------------- | -------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. |
**Example**
```js
let uuid = "";
let description = "";
volumemanager.setVolumeDescription(uuid, description).then(function() {
console.info("setVolumeDescription successfully");
}).catch(function(error){
console.info("setVolumeDescription failed with error:"+ error);
});
```
## volumemanager.setVolumeDescription
setVolumeDescription(uuid: string, description: string, callback: AsyncCallback&lt;void&gt;): void
Asynchronously sets the volume description based on the UUID. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MOUNT_UNMOUNT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | ---------------- |
| uuid | string | Yes | UUID of the volume. |
| description | string | Yes | Volume description. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Example**
```js
let uuid = "";
let description = "";
volumemanager.setVolumeDescription(uuid, description, (error, bool) => {
// Do something.
});
```
## volumemanager.format
format(volumeId: string, fsType: string): Promise&lt;void&gt;
Asynchronously formats a volume. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MOUNT_FORMAT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description|
| ----------- | ------ | ---- | ---- |
| volumeId | string | Yes | Volume ID.|
| fsType | string | Yes | File system type.|
**Return value**
| Type | Description |
| ---------------------- | ---------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
let volumeId = "";
let fsType = "";
volumemanager.format(volumeId, fsType).then(function() {
console.info("format successfully");
}).catch(function(error){
console.info("format failed with error:"+ error);
});
```
## volumemanager.format
format(volumeId: string, fsType: string, callback: AsyncCallback&lt;void&gt;): void
Asynchronously formats a volume. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MOUNT_FORMAT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- |
| volumeId | string | Yes | Volume ID. |
| fsType | string | Yes | File system type.|
| callback | AsyncCallback&lt;void&gt; | Yes | Called after the volume is formatted. |
**Example**
```js
let volumeId = "";
let fsType = "";
volumemanager.format(volumeId, fsType, (error, bool) => {
// Do something.
});
```
## volumemanager.partition
partition(diskId: string, type: number): Promise&lt;void&gt;
Asynchronously partitions a disk. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MOUNT_FORMAT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description|
| ----------- | ------ | ---- | ---- |
| diskId | string | Yes | ID of the disk to which the volume belongs.|
| type | number | Yes | Partition type. |
**Return value**
| Type | Description |
| --------------------- | ----------------------- |
| Promise&lt;void&gt; | Promise used to return the result. |
**Example**
```js
let diskId = "";
let type = 0;
volumemanager.partition(diskId, type).then(function() {
console.info("partition successfully");
}).catch(function(error){
console.info("partition failed with error:"+ error);
});
```
## volumemanager.partition
partition(diskId: string, type: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously partitions a disk. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MOUNT_FORMAT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------------- |
| diskId | string | Yes | ID of the disk to which the volume belongs. |
| type | number | Yes | Partition type. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
```js
let diskId = "";
let type = 0;
volumemanager.partition(diskId, type, (error, bool) => {
// Do something.
});
```
## Volume
**System capability**: SystemCapability.FileManagement.StorageService.Volume
### Attributes
| Name | Type | Readable | Writable | Description |
| ----------- | ------- | ------- | ----- | -------------------- |
| id | string | Yes| No| Volume ID. |
| uuid | string | Yes| No| UUID of the volume. |
| diskId | string | Yes| No| ID of the disk to which the volume belongs. |
| description | string | Yes| No| Description of the volume. |
| removable | boolean | Yes| No| Whether the volume is a removable storage device.|
| state | number | Yes| No| Volume state. |
| path | string | Yes| No| Mount address of the volume. |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册