提交 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. |
......@@ -25,9 +25,9 @@ Obtains information about all wants with **extension** set to **fileAccess** in
**Return value**
| Type| Description|
| --- | -- |
| Promise&lt;Array&lt;Want&gt;&gt; | Promise used to return the **want** information obtained.|
| Type| Description|
| --- | -- |
| Promise&lt;Array&lt;Want&gt;&gt; | Promise used to return the **want** information obtained.|
**Example**
......@@ -55,9 +55,9 @@ Obtains information about all wants with **extension** set to **fileAccess** in
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;Array&lt;Want&gt;&gt; | Yes| Promise used to return the **want** information obtained.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;Array&lt;Want&gt;&gt; | Yes| Promise used to return the **want** information obtained.|
**Example**
......@@ -89,16 +89,16 @@ Synchronously creates a **Helper** object to connect to the specified wants. The
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
| wants | Array&lt;Want&gt; | Yes| Wants to connect.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
| wants | Array&lt;Want&gt; | Yes| Wants to connect.|
**Return value**
| Type| Description|
| --- | -- |
| FileAccessHelper | **Helper** object created.|
| Type| Description|
| --- | -- |
| FileAccessHelper | **Helper** object created.|
**Example**
......@@ -136,26 +136,26 @@ Synchronously creates a **Helper** object to connect to all file management serv
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
**Return value**
| Type| Description|
| --- | -- |
| FileAccessHelper | **Helper** object created.|
| Type| Description|
| --- | -- |
| FileAccessHelper | **Helper** object created.|
**Example**
```js
createFileAccessHelper() {
let fileAccesssHelperAllServer = null;
let fileAccessHelperAllServer = null;
// Create a Helper object to interact with all file management services configured with fileAccess in the system.
try {
// this.context is passed by EntryAbility.
fileAccesssHelperAllServer = fileAccess.createFileAccessHelper(this.context);
if (!fileAccesssHelperAllServer)
fileAccessHelperAllServer = fileAccess.createFileAccessHelper(this.context);
if (!fileAccessHelperAllServer)
console.error("createFileAccessHelper interface returns an undefined object");
} catch (error) {
console.error("createFileAccessHelper failed, errCode:" + error.code + ", errMessage:" + error.message);
......@@ -175,9 +175,9 @@ Obtains information about the device root nodes of the file management service t
**Return value**
| Type| Description|
| --- | -- |
| Promise&lt;RootIterator&gt; | Promise used to return the **RootIterator** object obtained.|
| Type| Description|
| --- | -- |
| Promise&lt;RootIterator&gt; | Promise used to return the **RootIterator** object obtained.|
**Example**
......@@ -210,7 +210,9 @@ Obtains information about the device root nodes of the file management service t
getRoots(callback:AsyncCallback&lt;RootIterator&gt;) : void;
Obtains information about the device root nodes of the file management service type connected to the **Helper** object. This API uses an asynchronous callback to return the result. The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo) through [next()](#rootiteratornext).
Obtains information about the device root nodes of the file management service type connected to the **Helper** object. This API uses an asynchronous callback to return the result.
The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo) through [next()](#rootiteratornext).
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -218,9 +220,9 @@ Obtains information about the device root nodes of the file management service t
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;RootIterator&gt; | Yes| Promise used to return the **RootIterator** object obtained.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;RootIterator&gt; | Yes| Promise used to return the **RootIterator** object obtained.|
**Example**
......@@ -253,7 +255,7 @@ Obtains information about the device root nodes of the file management service t
listFile(filter?: Filter) : FileIterator
Synchronously obtains the **FileIterator** object of the first-level files (file folder) matching the conditions of the filter from the device root node. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext).
Synchronously obtains the **FileIterator** object of the first-level files (directory) matching the conditions of the filter from the device root node. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext).
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -261,16 +263,16 @@ Synchronously obtains the **FileIterator** object of the first-level files (file
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
**Example**
......@@ -312,15 +314,15 @@ Recursively obtains the **FileIterator** object of the files matching the condit
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
**Example**
......@@ -354,7 +356,7 @@ Recursively obtains the **FileIterator** object of the files matching the condit
listFile(filter?: Filter) : FileIterator
Synchronously obtains the **FileIterator** object of the next-level files (file folders) matching the conditions of the filter from a directory. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext).
Synchronously obtains the **FileIterator** object of the next-level files (directories) matching the conditions of the filter from a directory. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext).
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -362,15 +364,15 @@ Synchronously obtains the **FileIterator** object of the next-level files (file
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
**Example**
......@@ -412,16 +414,16 @@ Recursively obtains the **FileIterator** object of the files matching the condit
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
**Example**
......@@ -463,10 +465,10 @@ Creates a file in a directory. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
**Return value**
......@@ -508,11 +510,11 @@ Creates a file in a directory. This API uses an asynchronous callback to return
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file created.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file created.|
**Example**
......@@ -540,7 +542,7 @@ Creates a file in a directory. This API uses an asynchronous callback to return
mkDir(parentUri: string, displayName: string) : Promise&lt;string&gt;
Creates a folder in a directory. This API uses a promise to return the result.
Creates a directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -548,16 +550,16 @@ Creates a folder in a directory. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the folder to create.|
| displayName | string | Yes| Name of the folder to create.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the directory to create.|
| displayName | string | Yes| Name of the directory to create.|
**Return value**
| Type| Description|
| --- | -- |
| Promise&lt;string&gt; | Promise used to return the URI of the folder created.|
| Promise&lt;string&gt; | Promise used to return the URI of the directory created.|
**Example**
......@@ -585,7 +587,7 @@ Creates a folder in a directory. This API uses a promise to return the result.
mkDir(parentUri: string, displayName: string, callback: AsyncCallback&lt;string&gt;) : void;
Creates a folder in a directory. This API uses an asynchronous callback to return the result.
Creates a directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -593,11 +595,11 @@ Creates a folder in a directory. This API uses an asynchronous callback to retur
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the folder to create.|
| displayName | string | Yes| Name of the folder to create.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the folder created.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the directory to create.|
| displayName | string | Yes| Name of the directory to create.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the directory created.|
**Example**
......@@ -633,10 +635,10 @@ Opens a file. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
**Return value**
......@@ -671,11 +673,11 @@ Opens a file. This API uses an asynchronous callback to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the file descriptor of the file opened.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the file descriptor of the file opened.|
**Example**
......@@ -702,7 +704,7 @@ Opens a file. This API uses an asynchronous callback to return the result.
delete(uri: string) : Promise&lt;number&gt;
Deletes a file or folder. This API uses a promise to return the result.
Deletes a file or directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -710,9 +712,9 @@ Deletes a file or folder. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or folder to delete.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to delete.|
**Return value**
......@@ -741,7 +743,7 @@ Deletes a file or folder. This API uses a promise to return the result.
delete(uri: string, callback: AsyncCallback&lt;number&gt;) : void;
Deletes a file or folder. This API uses an asynchronous callback to return the result.
Deletes a file or directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -749,10 +751,10 @@ Deletes a file or folder. This API uses an asynchronous callback to return the r
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or folder to delete.|
| callback | AsyncCallback&lt;number&gt; | Yes| Promise used to return the result.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to delete.|
| callback | AsyncCallback&lt;number&gt; | Yes| Promise used to return the result.|
**Example**
......@@ -779,7 +781,7 @@ Deletes a file or folder. This API uses an asynchronous callback to return the r
move(sourceFile: string, destFile: string) : Promise&lt;string&gt;
Moves a file or folder. This API uses a promise to return the result.
Moves a file or directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -787,22 +789,22 @@ Moves a file or folder. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or folder to move.|
| destFile | string | Yes| URI of the folder to which the file or folder will be moved.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or directory to move.|
| destFile | string | Yes| URI of the directory, to which the file or directory will be moved.|
**Return value**
| Type| Description|
| ----- | ------ |
| Promise&lt;string&gt; | Promise used to return the URI of the file or folder in the destination directory.|
| Promise&lt;string&gt; | Promise used to return the URI of the file or directory in the destination directory.|
**Example**
```js
// The media library URI is used as an example.
//In the sample code, sourceFile destFile indicates the file or folder in the Download directory. The URI is the URI in fileInfo.
//In the sample code, sourceFile destFile indicates the file or directory in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained.
let sourceFile = "datashare:///media/file/102";
let destFile = "datashare:///media/file/101";
......@@ -819,7 +821,7 @@ Moves a file or folder. This API uses a promise to return the result.
move(sourceFile: string, destFile: string, callback: AsyncCallback&lt;string&gt;) : void;
Moves a file or folder. This API uses an asynchronous callback to return the result.
Moves a file or directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -827,17 +829,17 @@ Moves a file or folder. This API uses an asynchronous callback to return the res
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or folder to move.|
| destFile | string | Yes| URI of the folder to which the file or folder will be moved.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file or folder in the destination directory.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or directory to move.|
| destFile | string | Yes| URI of the directory, to which the file or directory will be moved.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file or directory in the destination directory.|
**Example**
```js
// The media library URI is used as an example.
//In the sample code, sourceFile destFile indicates the file or folder in the Download directory. The URI is the URI in fileInfo.
//In the sample code, sourceFile destFile indicates the file or directory in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained.
let sourceFile = "datashare:///media/file/102";
let destFile = "datashare:///media/file/101";
......@@ -859,7 +861,7 @@ Moves a file or folder. This API uses an asynchronous callback to return the res
rename(uri: string, displayName: string) : Promise&lt;string&gt;
Renames a file or folder. 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.UserFileService
......@@ -867,16 +869,16 @@ Renames a file or folder. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or folder to rename.|
| displayName | string | Yes| New name of the file or folder, which can contain the file name extension.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to rename.|
| displayName | string | Yes| New name of the file or directory, which can contain the file name extension.|
**Return value**
| Type| Description|
| --- | -- |
| Promise&lt;string&gt; | Promise used to return the URI of the renamed file or folder.|
| Promise&lt;string&gt; | Promise used to return the URI of the renamed file or directory.|
**Example**
......@@ -898,7 +900,7 @@ Renames a file or folder. This API uses a promise to return the result.
rename(uri: string, displayName: string, callback: AsyncCallback&lt;string&gt;) : void;
Renames a file or folder. 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.UserFileService
......@@ -906,11 +908,11 @@ Renames a file or folder. This API uses an asynchronous callback to return the r
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or folder to rename.|
| displayName | string | Yes| New name of the file or folder, which can contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the renamed file or folder.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to rename.|
| displayName | string | Yes| New name of the file or directory, which can contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the renamed file or directory.|
**Example**
......@@ -937,7 +939,7 @@ Renames a file or folder. This API uses an asynchronous callback to return the r
access(sourceFileUri: string) : Promise&lt;boolean&gt;
Checks whether a file or folder exists. This API uses a promise to return the result.
Checks whether a file or directory exists. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -945,9 +947,9 @@ Checks whether a file or folder exists. This API uses a promise to return the re
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or folder.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or directory.|
**Return value**
......@@ -978,7 +980,7 @@ Checks whether a file or folder exists. This API uses a promise to return the re
access(sourceFileUri: string, callback: AsyncCallback&lt;boolean&gt;) : void;
Checks whether a file or folder exists. This API uses an asynchronous callback to return the result.
Checks whether a file or directory exists. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -986,10 +988,10 @@ Checks whether a file or folder exists. This API uses an asynchronous callback t
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or folder.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Promise used to return the result.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or directory.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Promise used to return the result.|
**Example**
......@@ -1029,13 +1031,13 @@ Obtains the next-level device root directory. **RootIterator** is an iterator ob
| Type| Description|
| --- | -- |
| {value: RootInfo, done: boolean} | Root directory information obtained. This API traverses the folder until **done** returns **true**. The **value** field contains the root directory information.|
| {value: RootInfo, done: boolean} | Root directory information obtained. This API traverses the directory until **done** returns **true**. The **value** field contains the root directory information.|
## FileIterator.next
next( ) : { value: FileInfo, done: boolean }
Obtains the information about the next-level file or folder. **FileIterator** is an iterator object of a folder.
Obtains the information about the next-level file or directory. **FileIterator** is an iterator object of a directory.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -1045,7 +1047,7 @@ Obtains the information about the next-level file or folder. **FileIterator** is
| Type| Description|
| --- | -- |
| {value: FileInfo, done: boolean} | File or folder information obtained. This API traverses the specified folder until **done** returns **true**. The **value** field contains the file or folder information obtained.|
| {value: FileInfo, done: boolean} | File or directory information obtained. This API traverses the specified directory until **done** returns **true**. The **value** field contains the file or directory information obtained.|
## RootInfo
......@@ -1066,7 +1068,7 @@ Represents the root attribute information and interface capabilities of a device
## FileInfo
Represents the file or folder attribute information and interface capabilities.
Represents the file or directory attribute information and interface capabilities.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -1076,12 +1078,12 @@ Represents the file or folder attribute information and interface capabilities.
| Name| Type | Readable| Writable| Description |
| ------ | ------ | -------- | ------ | -------- |
| uri | string | Yes| No| URI of the file or folder.|
| fileName | string | Yes| No| Name of a file or folder.|
| mode | number | Yes| No| Permissions on the file or folder.|
| size | number | Yes| No| Size of the file or folder.|
| mtime | number | Yes| No| Time when the file or folder was last modified.|
| mimeType | string | Yes| No| MIME type of the file or folder.|
| uri | string | Yes| No| URI of the file or directory.|
| fileName | string | Yes| No| Name of a file or directory.|
| mode | number | Yes| No| Permissions on the file or directory.|
| size | number | Yes| No| Size of the file or directory.|
| mtime | number | Yes| No| Time when the file or directory was last modified.|
| mimeType | string | Yes| No| MIME type of the file or directory.|
## OPENFLAGS
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册