diff --git a/en/application-dev/reference/apis/js-apis-convertxml.md b/en/application-dev/reference/apis/js-apis-convertxml.md
index 70d35b6cb168e6f10b847a42bdefa8fd53eb3d40..4c66c928fb7ee6c5482d39db7b39acaa6793691e 100644
--- a/en/application-dev/reference/apis/js-apis-convertxml.md
+++ b/en/application-dev/reference/apis/js-apis-convertxml.md
@@ -47,21 +47,27 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
**Example**
```js
-let xml =
- '' +
- '' +
- ' Happy' +
- ' Work' +
- ' Play' +
- '';
-let conv = new convertxml.ConvertXML()
-let options = {trim : false, declarationKey:"_declaration",
- instructionKey : "_instruction", attributesKey : "_attributes",
- textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype",
- commentKey : "_comment", parentKey : "_parent", typeKey : "_type",
- nameKey : "_name", elementsKey : "_elements"}
-let result = JSON.stringify(conv.convertToJSObject(xml, options));
-console.log(result);
+try {
+ let xml =
+ '' +
+ '' +
+ ' Happy' +
+ ' Work' +
+ ' Play' +
+ '';
+ let conv = new convertxml.ConvertXML()
+ let options = {
+ trim: false, declarationKey: "_declaration",
+ instructionKey: "_instruction", attributesKey: "_attributes",
+ textKey: "_text", cdataKey: "_cdata", doctypeKey: "_doctype",
+ commentKey: "_comment", parentKey: "_parent", typeKey: "_type",
+ nameKey: "_name", elementsKey: "_elements"
+ }
+ let result = JSON.stringify(conv.convertToJSObject(xml, options));
+ console.log(result);
+} catch (e) {
+ console.log(e.toString());
+}
// Output (non-compact)
// {"_declaration":{"_attributes":{"version":"1.0","encoding":"utf-8"}},"_elements":[{"_type":"element","_name":"note","_attributes":{"importance":"high","logged":"true"},"_elements":[{"_type":"element","_name":"title","_elements":[{"_type":"text","_text":"Happy"}]},{"_type":"element","_name":"todo","_elements":[{"_type":"text","_text":"Work"}]},{"_type":"element","_name":"todo","_elements":[{"_type":"text","_text":"Play"}]}]}]}
```
diff --git a/en/application-dev/reference/apis/js-apis-medialibrary.md b/en/application-dev/reference/apis/js-apis-medialibrary.md
index 0ee9b746e29fd8bb0473b664a1acabd0f2f157ae..cd52a40c909762b31e033274b2b5193ecf34e6f6 100644
--- a/en/application-dev/reference/apis/js-apis-medialibrary.md
+++ b/en/application-dev/reference/apis/js-apis-medialibrary.md
@@ -34,6 +34,7 @@ This API can be used only in the stage model.
**Example (from API version 9)**
```ts
+// Obtain a MediaLibrary instance. The instance obtained here is used in later.
const context = getContext(this);
let media = mediaLibrary.getMediaLibrary(context);
```
@@ -92,46 +93,59 @@ Obtains file assets (also called files). This API uses an asynchronous callback
**Example**
```js
-let fileKeyObj = mediaLibrary.FileKey;
-let imageType = mediaLibrary.MediaType.IMAGE;
-let imagesFetchOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
-};
-media.getFileAssets(imagesFetchOp, (error, fetchFileResult) => {
- if (fetchFileResult == undefined) {
- console.error('Failed to get fetchFileResult: ' + error);
- return;
- }
- const count = fetchFileResult.getCount();
- if (count < 0) {
- console.error('Failed to get count from fetchFileResult: count: ' + count);
- return;
- }
- if (count == 0) {
- console.info('The count of fetchFileResult is zero');
- return;
- }
-
- console.info('Get fetchFileResult success, count: ' + count);
- fetchFileResult.getFirstObject((err, fileAsset) => {
- if (fileAsset == undefined) {
- console.error('Failed to get first object: ' + err);
+async function example() {
+ let fileKeyObj = mediaLibrary.FileKey;
+ let imageType = mediaLibrary.MediaType.IMAGE;
+ // Create options for fetching the files. The options are used to obtain files of the image type.
+ let imagesFetchOp = {
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ };
+ // Obtain the files in asynchronous callback mode.
+ media.getFileAssets(imagesFetchOp, (error, fetchFileResult) => {
+ // Check whether the result set of the obtained files is undefined. If yes, the API call fails.
+ if (fetchFileResult == undefined) {
+ console.error('get fetchFileResult failed with error: ' + error);
return;
}
- console.info('fileAsset.displayName ' + ': ' + fileAsset.displayName);
- for (let i = 1; i < count; i++) {
- fetchFileResult.getNextObject((err, fileAsset) => {
- if (fileAsset == undefined) {
- console.error('Failed to get next object: ' + err);
- return;
- }
- console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName);
- })
+ // Obtain the total number of files in the result set.
+ const count = fetchFileResult.getCount();
+ // Check whether the number is less than 0. If yes, the API call fails.
+ if (count < 0) {
+ console.error('get count from fetchFileResult failed, count: ' + count);
+ return;
}
+ // Check whether the number is 0. If yes, the API call is successful, but the result set is empty. Check whether the options for fetching the files are correctly set and whether the corresponding files exist on the device.
+ if (count == 0) {
+ console.info('The count of fetchFileResult is zero');
+ return;
+ }
+ console.info('Get fetchFileResult successfully, count: ' + count);
+ // Obtain the first file in the result set in asynchronous callback mode.
+ fetchFileResult.getFirstObject((error, fileAsset) => {
+ // Check whether the first file is undefined. If yes, the API call fails.
+ if (fileAsset == undefined) {
+ console.error('get first object failed with error: ' + error);
+ return;
+ }
+ console.info('fileAsset.displayName ' + '0 : ' + fileAsset.displayName);
+ // Call getNextObject to obtain the next file until the last one.
+ for (let i = 1; i < count; i++) {
+ fetchFileResult.getNextObject((error, fileAsset) => {
+ if (fileAsset == undefined) {
+ console.error('get next object failed with error: ' + error);
+ return;
+ }
+ console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName);
+ })
+ }
+ });
+ // Release the FetchFileResult instance and invalidate it. Other APIs can no longer be called.
+ fetchFileResult.close();
});
-});
+}
```
+
### getFileAssets7+
getFileAssets(options: MediaFetchOptions): Promise<FetchFileResult>
@@ -157,38 +171,51 @@ Obtains file assets. This API uses a promise to return the result.
**Example**
```js
-let fileKeyObj = mediaLibrary.FileKey;
-let imageType = mediaLibrary.MediaType.IMAGE;
-let imagesFetchOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
-};
-media.getFileAssets(imagesFetchOp).then(function(fetchFileResult) {
- const count = fetchFileResult.getCount();
- if (count < 0) {
- console.error('Failed to get count from fetchFileResult: count: ' + count);
- return;
- }
- if (count == 0) {
- console.info('The count of fetchFileResult is zero');
- return;
- }
- console.info('Get fetchFileResult success, count: ' + count);
- fetchFileResult.getFirstObject().then(function(fileAsset) {
- console.info('fileAsset.displayName ' + ': ' + fileAsset.displayName);
- for (let i = 1; i < count; i++) {
- fetchFileResult.getNextObject().then(function(fileAsset) {
- console.info('fileAsset.displayName ' + ': ' + fileAsset.displayName);
- }).catch(function(err) {
- console.error('Failed to get next object: ' + err);
- })
+async function example() {
+ let fileKeyObj = mediaLibrary.FileKey;
+ let imageType = mediaLibrary.MediaType.IMAGE;
+ // Create options for fetching the files. The options are used to obtain files of the image type.
+ let imagesFetchOp = {
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ };
+ // Obtain the files in promise mode.
+ media.getFileAssets(imagesFetchOp).then((fetchFileResult) => {
+ // Obtain the total number of files in the result set.
+ const count = fetchFileResult.getCount();
+ // Check whether the number is less than 0. If yes, the API call fails.
+ if (count < 0) {
+ console.error('get count from fetchFileResult failed, count: ' + count);
+ return;
}
- }).catch(function(err) {
- console.error('Failed to get first object: ' + err);
+ // Check whether the number is 0. If yes, the API call is successful, but the result set is empty. Check whether the options for fetching the files are correctly set and whether the corresponding files exist on the device.
+ if (count == 0) {
+ console.info('The count of fetchFileResult is zero');
+ return;
+ }
+ console.info('Get fetchFileResult successfully, count: ' + count);
+ // Obtain the first file in the result set in promise mode.
+ fetchFileResult.getFirstObject().then((fileAsset) => {
+ console.info('fileAsset.displayName ' + '0 : ' + fileAsset.displayName);
+ // Call getNextObject to obtain the next file until the last one.
+ for (let i = 1; i < count; i++) {
+ fetchFileResult.getNextObject().then((fileAsset) => {
+ console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName);
+ }).catch((error) => {
+ console.error('get next object failed with error: ' + error);
+ })
+ }
+ }).catch((error) => {
+ // Calling getFirstObject fails.
+ console.error('get first object failed with error: ' + error);
+ });
+ // Release the FetchFileResult instance and invalidate it. Other APIs can no longer be called.
+ fetchFileResult.close();
+ }).catch((error) => {
+ // Calling getFileAssets fails.
+ console.error('get file assets failed with error: ' + error);
});
-}).catch(function(err){
- console.error("Failed to get file assets: " + err);
-});
+}
```
### on8+
@@ -232,7 +259,7 @@ Unsubscribes from the media library changes. This API uses an asynchronous callb
```js
media.off('imageChange', () => {
- // stop listening success
+ // Stop listening successfully.
})
```
@@ -263,11 +290,11 @@ async function example() {
let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE);
- media.createAsset(mediaType, 'imageCallBack.jpg', path + 'myPicture/', (err, fileAsset) => {
+ media.createAsset(mediaType, 'imageCallBack.jpg', path + 'myPicture/', (error, fileAsset) => {
if (fileAsset != undefined) {
console.info('createAsset successfully, message');
} else {
- console.error('createAsset failed, message = ' + err);
+ console.error('createAsset failed with error: ' + error);
}
});
}
@@ -307,8 +334,8 @@ async function example() {
const path = await media.getPublicDirectory(DIR_IMAGE);
media.createAsset(mediaType, 'imagePromise.jpg', path + 'myPicture/').then((fileAsset) => {
console.info('createAsset successfully, message = ' + JSON.stringify(fileAsset));
- }).catch((err) => {
- console.error('createAsset failed, message = ' + err);
+ }).catch((error) => {
+ console.error('createAsset failed with error: ' + error);
});
}
```
@@ -349,14 +376,15 @@ async function example() {
const fetchFileResult = await media.getFileAssets(option);
let asset = await fetchFileResult.getFirstObject();
if (asset == undefined) {
- console.error('asset not exist')
- return
+ console.error('asset not exist');
+ return;
}
media.deleteAsset(asset.uri).then(() => {
- console.info("deleteAsset successfully");
- }).catch((err) => {
- console.error("deleteAsset failed with error:"+ err);
+ console.info('deleteAsset successfully');
+ }).catch((error) => {
+ console.error('deleteAsset failed with error: ' + error);
});
+ fetchFileResult.close();
}
```
@@ -391,16 +419,17 @@ async function example() {
const fetchFileResult = await media.getFileAssets(option);
let asset = await fetchFileResult.getFirstObject();
if (asset == undefined) {
- console.error('asset not exist')
- return
+ console.error('asset not exist');
+ return;
}
- media.deleteAsset(asset.uri, (err) => {
- if (err != undefined) {
- console.info("deleteAsset successfully");
+ media.deleteAsset(asset.uri, (error) => {
+ if (error != undefined) {
+ console.error('deleteAsset failed with error: ' + error);
} else {
- console.error("deleteAsset failed with error:"+ err);
+ console.info('deleteAsset successfully');
}
});
+ fetchFileResult.close();
}
```
@@ -423,11 +452,11 @@ Obtains a public directory. This API uses an asynchronous callback to return the
```js
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
-media.getPublicDirectory(DIR_CAMERA, (err, dicResult) => {
+media.getPublicDirectory(DIR_CAMERA, (error, dicResult) => {
if (dicResult == 'Camera/') {
- console.info('mediaLibraryTest : getPublicDirectory passed');
+ console.info('getPublicDirectory DIR_CAMERA successfully');
} else {
- console.error('mediaLibraryTest : getPublicDirectory failed');
+ console.error('getPublicDirectory DIR_CAMERA failed with error: ' + error);
}
});
```
@@ -457,12 +486,15 @@ Obtains a public directory. This API uses a promise to return the result.
```js
async function example() {
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
- const dicResult = await media.getPublicDirectory(DIR_CAMERA);
- if (dicResult == 'Camera/') {
- console.info('MediaLibraryTest : getPublicDirectory');
- } else {
- console.error('MediaLibraryTest : getPublicDirectory failed');
- }
+ media.getPublicDirectory(DIR_CAMERA).then((dicResult) => {
+ if (dicResult == 'Camera/') {
+ console.info('getPublicDirectory DIR_CAMERA successfully');
+ } else {
+ console.error('getPublicDirectory DIR_CAMERA failed');
+ }
+ }).catch((error) => {
+ console.error('getPublicDirectory failed with error: ' + error);
+ });
}
```
@@ -486,19 +518,19 @@ Obtains the albums. This API uses an asynchronous callback to return the result.
**Example**
```js
-let AlbumNoArgsfetchOp = {
- selections: '',
- selectionArgs: [],
-};
-media.getAlbums(AlbumNoArgsfetchOp, (err, albumList) => {
- if (albumList != undefined) {
- const album = albumList[0];
- console.info('album.albumName = ' + album.albumName);
- console.info('album.count = ' + album.count);
- } else {
- console.error('getAlbum fail, message = ' + err);
- }
-})
+async function example() {
+ let AlbumNoArgsfetchOp = {
+ selections: '',
+ selectionArgs: [],
+ };
+ media.getAlbums(AlbumNoArgsfetchOp, (error, albumList) => {
+ if (albumList != undefined) {
+ console.info('getAlbums successfully: ' + JSON.stringify(albumList));
+ } else {
+ console.error('getAlbums failed with error: ' + error);
+ }
+ })
+}
```
### getAlbums7+
@@ -526,15 +558,17 @@ Obtains the albums. This API uses a promise to return the result.
**Example**
```js
-let AlbumNoArgsfetchOp = {
- selections: '',
- selectionArgs: [],
-};
-media.getAlbums(AlbumNoArgsfetchOp).then(function(albumList){
- console.info("getAlbums successfully:"+ JSON.stringify(albumList));
-}).catch(function(err){
- console.error("getAlbums failed with error: " + err);
-});
+async function example() {
+ let AlbumNoArgsfetchOp = {
+ selections: '',
+ selectionArgs: [],
+ };
+ media.getAlbums(AlbumNoArgsfetchOp).then((albumList) => {
+ console.info('getAlbums successfully: ' + JSON.stringify(albumList));
+ }).catch((error) => {
+ console.error('getAlbums failed with error: ' + error);
+ });
+}
```
### release8+
@@ -550,12 +584,12 @@ Call this API when you no longer need to use the APIs in the **MediaLibrary** in
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------- |
-| callback | AsyncCallback<void> | Yes | Callback used to return the execution result.|
+| callback | AsyncCallback<void> | Yes | Callback that returns no value.|
**Example**
```js
-media.release((err) => {
+media.release(() => {
// do something
});
```
@@ -604,16 +638,16 @@ Stores a media asset. This API uses an asynchronous callback to return the URI t
```js
let option = {
- src : "/data/storage/el2/base/haps/entry/image.png",
- mimeType : "image/*",
- relativePath : "Pictures/"
+ src : '/data/storage/el2/base/haps/entry/image.png',
+ mimeType : 'image/*',
+ relativePath : 'Pictures/'
};
-mediaLibrary.getMediaLibrary().storeMediaAsset(option, (err, value) => {
- if (err) {
- console.error("An error occurred when storing media resources.");
+mediaLibrary.getMediaLibrary().storeMediaAsset(option, (error, value) => {
+ if (error) {
+ console.error('storeMediaAsset failed with error: ' + error);
return;
}
- console.info("Media resources stored. ");
+ console.info('Media resources stored. ');
// Obtain the URI that stores the media asset.
});
```
@@ -647,15 +681,15 @@ Stores a media asset. This API uses a promise to return the URI that stores the
```js
let option = {
- src : "/data/storage/el2/base/haps/entry/image.png",
- mimeType : "image/*",
- relativePath : "Pictures/"
+ src : '/data/storage/el2/base/haps/entry/image.png',
+ mimeType : 'image/*',
+ relativePath : 'Pictures/'
};
mediaLibrary.getMediaLibrary().storeMediaAsset(option).then((value) => {
- console.info("Media resources stored.");
+ console.info('Media resources stored.');
// Obtain the URI that stores the media asset.
-}).catch((err) => {
- console.error("An error occurred when storing media resources.");
+}).catch((error) => {
+ console.error('storeMediaAsset failed with error: ' + error);
});
```
@@ -676,7 +710,7 @@ Starts image preview, with the first image to preview specified. This API can be
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------------------------- |
-| images | Array<string> | Yes | URIs of the images to preview. The value can start with either **https://** or **datashare://**.|
+| images | Array<string> | Yes | URIs of the images to preview. The value can start with either **'https://'** or **'datashare://'**.|
| index | number | Yes | Index of the first image to preview. |
| callback | AsyncCallback<void> | Yes | Callback used to return the image preview result. If the preview fails, an error message is returned. |
@@ -684,22 +718,22 @@ Starts image preview, with the first image to preview specified. This API can be
```js
let images = [
- "datashare:///media/xxxx/2",
- "datashare:///media/xxxx/3"
+ 'datashare:///media/xxxx/2',
+ 'datashare:///media/xxxx/3'
];
/* Preview online images.
let images = [
- "https://media.xxxx.com/image1.jpg",
- "https://media.xxxx.com/image2.jpg"
+ 'https://media.xxxx.com/image1.jpg',
+ 'https://media.xxxx.com/image2.jpg'
];
*/
let index = 1;
-mediaLibrary.getMediaLibrary().startImagePreview(images, index, (err) => {
- if (err) {
- console.error("An error occurred when previewing the images.");
+mediaLibrary.getMediaLibrary().startImagePreview(images, index, (error) => {
+ if (error) {
+ console.error('startImagePreview failed with error: ' + error);
return;
}
- console.info("Succeeded in previewing the images.");
+ console.info('Succeeded in previewing the images.');
});
```
@@ -720,28 +754,28 @@ Starts image preview. This API can be used to preview local images whose URIs st
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------------------------- |
-| images | Array<string> | Yes | URIs of the images to preview. The value can start with either **https://** or **datashare://**.|
+| images | Array<string> | Yes | URIs of the images to preview. The value can start with either **'https://'** or **'datashare://'**.|
| callback | AsyncCallback<void> | Yes | Callback used to return the image preview result. If the preview fails, an error message is returned. |
**Example**
```js
let images = [
- "datashare:///media/xxxx/2",
- "datashare:///media/xxxx/3"
+ 'datashare:///media/xxxx/2',
+ 'datashare:///media/xxxx/3'
];
/* Preview online images.
let images = [
- "https://media.xxxx.com/image1.jpg",
- "https://media.xxxx.com/image2.jpg"
+ 'https://media.xxxx.com/image1.jpg',
+ 'https://media.xxxx.com/image2.jpg'
];
*/
-mediaLibrary.getMediaLibrary().startImagePreview(images, (err) => {
- if (err) {
- console.error("An error occurred when previewing the images.");
+mediaLibrary.getMediaLibrary().startImagePreview(images, (error) => {
+ if (error) {
+ console.error('startImagePreview failed with error: ' + error);
return;
}
- console.info("Succeeded in previewing the images.");
+ console.info('Succeeded in previewing the images.');
});
```
@@ -762,7 +796,7 @@ Starts image preview, with the first image to preview specified. This API can be
| Name | Type | Mandatory | Description |
| ------ | ------------------- | ---- | ---------------------------------------- |
-| images | Array<string> | Yes | URIs of the images to preview. The value can start with either **https://** or **datashare://**.|
+| images | Array<string> | Yes | URIs of the images to preview. The value can start with either **'https://'** or **'datashare://'**.|
| index | number | No | Index of the first image to preview. If this parameter is not specified, the default value **0** is used. |
**Return value**
@@ -775,20 +809,20 @@ Starts image preview, with the first image to preview specified. This API can be
```js
let images = [
- "datashare:///media/xxxx/2",
- "datashare:///media/xxxx/3"
+ 'datashare:///media/xxxx/2',
+ 'datashare:///media/xxxx/3'
];
/* Preview online images.
let images = [
- "https://media.xxxx.com/image1.jpg",
- "https://media.xxxx.com/image2.jpg"
+ 'https://media.xxxx.com/image1.jpg',
+ 'https://media.xxxx.com/image2.jpg'
];
*/
let index = 1;
mediaLibrary.getMediaLibrary().startImagePreview(images, index).then(() => {
- console.info("Succeeded in previewing the images.");
-}).catch((err) => {
- console.error("An error occurred when previewing the images.");
+ console.info('Succeeded in previewing the images.');
+}).catch((error) => {
+ console.error('startImagePreview failed with error: ' + error);
});
```
@@ -816,15 +850,15 @@ Starts media selection. This API uses an asynchronous callback to return the lis
```js
let option : mediaLibrary.MediaSelectOption = {
- type : "media",
+ type : 'media',
count : 2
};
-mediaLibrary.getMediaLibrary().startMediaSelect(option, (err, value) => {
- if (err) {
- console.error("An error occurred when selecting media resources.");
+mediaLibrary.getMediaLibrary().startMediaSelect(option, (error, value) => {
+ if (error) {
+ console.error('startMediaSelect failed with error: ' + error);
return;
}
- console.info("Media resources selected.");
+ console.info('Media resources selected.');
// Obtain the media selection value.
});
```
@@ -858,14 +892,14 @@ Starts media selection. This API uses a promise to return the list of URIs that
```js
let option : mediaLibrary.MediaSelectOption = {
- type : "media",
+ type : 'media',
count : 2
};
mediaLibrary.getMediaLibrary().startMediaSelect(option).then((value) => {
- console.info("Media resources selected.");
+ console.info('Media resources selected.');
// Obtain the media selection value.
-}).catch((err) => {
- console.error("An error occurred when selecting media resources.");
+}).catch((error) => {
+ console.error('startMediaSelect failed with error: ' + error);
});
```
@@ -893,14 +927,12 @@ Obtains information about online peer devices. This API uses a promise to return
async function example() {
media.getActivePeers().then((devicesInfo) => {
if (devicesInfo != undefined) {
- for (let i = 0; i < devicesInfo.length; i++) {
- console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
- }
+ console.info('get distributed info ' + JSON.stringify(devicesInfo));
} else {
- console.info('get distributed info is undefined!')
+ console.info('get distributed info is undefined!');
}
- }).catch((err) => {
- console.error("get distributed info failed with error:" + err);
+ }).catch((error) => {
+ console.error('get distributed info failed with error: ' + error);
});
}
```
@@ -927,15 +959,13 @@ Obtains information about online peer devices. This API uses an asynchronous cal
```js
async function example() {
- media.getActivePeers((err, devicesInfo) => {
+ media.getActivePeers((error, devicesInfo) => {
if (devicesInfo != undefined) {
- for (let i = 0; i < devicesInfo.length; i++) {
- console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
- }
+ console.info('get distributed info ' + JSON.stringify(devicesInfo));
} else {
- console.error('get distributed fail, message = ' + err)
+ console.error('get distributed failed with error: ' + error);
}
- })
+ });
}
```
@@ -964,14 +994,12 @@ Obtains information about all peer devices. This API uses a promise to return th
async function example() {
media.getAllPeers().then((devicesInfo) => {
if (devicesInfo != undefined) {
- for (let i = 0; i < devicesInfo.length; i++) {
- console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
- }
+ console.info('get distributed info ' + JSON.stringify(devicesInfo));
} else {
- console.info('get distributed info is undefined!')
+ console.info('get distributed info is undefined!');
}
- }).catch((err) => {
- console.error("get distributed info failed with error: " + err);
+ }).catch((error) => {
+ console.error('get distributed info failed with error: ' + error);
});
}
```
@@ -998,15 +1026,13 @@ Obtains information about online peer devices. This API uses an asynchronous cal
```js
async function example() {
- media.getAllPeers((err, devicesInfo) => {
+ media.getAllPeers((error, devicesInfo) => {
if (devicesInfo != undefined) {
- for (let i = 0; i < devicesInfo.length; i++) {
- console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
- }
+ console.info('get distributed info ' + JSON.stringify(devicesInfo));
} else {
- console.error('get distributed fail, message = ' + err)
+ console.error('get distributed failed with error: ' + error);
}
- })
+ });
}
```
@@ -1068,19 +1094,23 @@ Checks whether this file asset is a directory. This API uses an asynchronous cal
```js
async function example() {
- let fileKeyObj = mediaLibrary.FileKey
+ let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
- asset.isDirectory((err, isDirectory) => {
- // do something
+ asset.isDirectory((error, isDirectory) => {
+ if (error) {
+ console.error('isDirectory failed with error: ' + error);
+ } else {
+ console.info('isDirectory result:' + isDirectory);
+ }
});
+ fetchFileResult.close();
}
```
@@ -1104,21 +1134,21 @@ Checks whether this file asset is a directory. This API uses a promise to return
```js
async function example() {
- let fileKeyObj = mediaLibrary.FileKey
+ let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
- asset.isDirectory().then(function(isDirectory){
- console.info("isDirectory result:"+ isDirectory);
- }).catch(function(err){
- console.error("isDirectory failed with error: " + err);
+ asset.isDirectory().then((isDirectory) => {
+ console.info('isDirectory result:' + isDirectory);
+ }).catch((error) => {
+ console.error('isDirectory failed with error: ' + error);
});
+ fetchFileResult.close();
}
```
@@ -1142,20 +1172,20 @@ Commits the modification in this file asset to the database. This API uses an as
```js
async function example() {
- let fileKeyObj = mediaLibrary.FileKey
+ let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.title = 'newtitle';
asset.commitModify(() => {
- console.info('commitModify success');
+ console.info('commitModify successfully');
});
+ fetchFileResult.close();
}
```
@@ -1179,18 +1209,18 @@ Commits the modification in this file asset to the database. This API uses a pro
```js
async function example() {
- let fileKeyObj = mediaLibrary.FileKey
+ let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.title = 'newtitle';
- asset.commitModify();
+ await asset.commitModify();
+ fetchFileResult.close();
}
```
@@ -1200,9 +1230,7 @@ open(mode: string, callback: AsyncCallback<number>): void
Opens this file asset. This API uses an asynchronous callback to return the result.
-> **NOTE**
->
-> Currently, the write operations are mutually exclusive. After the write operation is complete, you must call **close** to release the resource.
+**NOTE**: When a file is opened in 'w' mode, the returned FD cannot be read. However, due to the implementation differences of file systems, some user-mode files opened in 'w' mode can be read by using FD. To perform the read or write operation on a file by using FD, you are advised to open the file in 'rw' mode. The write operations are mutually exclusive. After a write operation is complete, you must call **close** to release the resource.
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
@@ -1222,13 +1250,13 @@ async function example() {
let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE);
- const asset = await media.createAsset(mediaType, "image00003.jpg", path);
- asset.open('rw', (openError, fd) => {
- if(fd > 0){
- asset.close(fd);
- }else{
- console.error('File Open Failed!' + openError);
- }
+ const asset = await media.createAsset(mediaType, 'image00003.jpg', path);
+ asset.open('rw', (error, fd) => {
+ if (fd > 0) {
+ asset.close(fd);
+ } else {
+ console.error('File Open failed with error: ' + error);
+ }
});
}
```
@@ -1239,9 +1267,7 @@ open(mode: string): Promise<number>
Opens this file asset. This API uses a promise to return the result.
-> **NOTE**
->
-> Currently, the write operations are mutually exclusive. After the write operation is complete, you must call **close** to release the resource.
+**NOTE**: When a file is opened in 'w' mode, the returned FD cannot be read. However, due to the implementation differences of file systems, some user-mode files opened in 'w' mode can be read by using FD. To perform the read or write operation on a file by using FD, you are advised to open the file in 'rw' mode. The write operations are mutually exclusive. After a write operation is complete, you must call **close** to release the resource.
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
@@ -1266,14 +1292,12 @@ async function example() {
let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE);
- const asset = await media.createAsset(mediaType, "image00003.jpg", path);
- asset.open('rw')
- .then((fd) => {
- console.info('File fd!' + fd);
- })
- .catch((err) => {
- console.error('File err!' + err);
- });
+ const asset = await media.createAsset(mediaType, 'image00003.jpg', path);
+ asset.open('rw').then((fd) => {
+ console.info('File open fd: ' + fd);
+ }).catch((error) => {
+ console.error('File open failed with error: ' + error);
+ });
}
```
@@ -1298,30 +1322,28 @@ Closes this file asset. This API uses an asynchronous callback to return the res
```js
async function example() {
- let fileKeyObj = mediaLibrary.FileKey
+ let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.open('rw').then((fd) => {
- console.info('File fd!' + fd);
- asset.close(fd, (closeErr) => {
- if (closeErr != undefined) {
- console.error('mediaLibraryTest : close : FAIL ' + closeErr);
- console.error('mediaLibraryTest : ASSET_CALLBACK : FAIL');
+ console.info('File open fd: ' + fd);
+ asset.close(fd, (error) => {
+ if (error) {
+ console.error('asset.close failed with error: ' + error);
} else {
- console.info("=======asset.close success====>");
+ console.info('asset.close successfully');
}
});
- })
- .catch((err) => {
- console.error('File err!' + err);
+ }).catch((error) => {
+ console.error('File open failed with error: ' + error);
});
+ fetchFileResult.close();
}
```
@@ -1351,31 +1373,26 @@ Closes this file asset. This API uses a promise to return the result.
```js
async function example() {
- let fileKeyObj = mediaLibrary.FileKey
+ let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.open('rw').then((fd) => {
console.info('File fd!' + fd);
- asset.close(fd).then((closeErr) => {
- if (closeErr != undefined) {
- console.error('mediaLibraryTest : close : FAIL ' + closeErr);
- console.error('mediaLibraryTest : ASSET_CALLBACK : FAIL');
-
- } else {
- console.info("=======asset.close success====>");
- }
+ asset.close(fd).then(() => {
+ console.info('asset.close successfully');
+ }).catch((closeErr) => {
+ console.error('asset.close fail, closeErr: ' + closeErr);
});
- })
- .catch((err) => {
- console.error('File err!' + err);
+ }).catch((error) => {
+ console.error('open File failed with error: ' + error);
});
+ fetchFileResult.close();
}
```
@@ -1399,19 +1416,23 @@ Obtains the thumbnail of this file asset. This API uses an asynchronous callback
```js
async function example() {
- let fileKeyObj = mediaLibrary.FileKey
+ let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
- asset.getThumbnail((err, pixelmap) => {
- console.info('mediaLibraryTest : getThumbnail Successful '+ pixelmap);
+ asset.getThumbnail((error, pixelmap) => {
+ if (error) {
+ console.error('mediaLibrary getThumbnail failed with error: ' + error);
+ } else {
+ console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
+ }
});
+ fetchFileResult.close();
}
```
@@ -1439,17 +1460,21 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let size = { width: 720, height: 720 };
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
- asset.getThumbnail(size, (err, pixelmap) => {
- console.info('mediaLibraryTest : getThumbnail Successful '+ pixelmap);
+ asset.getThumbnail(size, (error, pixelmap) => {
+ if (error) {
+ console.error('mediaLibrary getThumbnail failed with error: ' + error);
+ } else {
+ console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
+ }
});
+ fetchFileResult.close();
}
```
@@ -1484,19 +1509,17 @@ async function example() {
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let size = { width: 720, height: 720 };
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
- asset.getThumbnail(size)
- .then((pixelmap) => {
- console.info('mediaLibraryTest : getThumbnail Successful '+ pixelmap);
- })
- .catch((err) => {
- console.error('mediaLibraryTest : getThumbnail fail, err: ' + err);
+ asset.getThumbnail(size).then((pixelmap) => {
+ console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
+ }).catch((error) => {
+ console.error('mediaLibrary getThumbnail failed with error: ' + error);
});
+ fetchFileResult.close();
}
```
@@ -1524,16 +1547,20 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
- asset.favorite(true,function(err){
- // do something
+ asset.favorite(true,(error) => {
+ if (error) {
+ console.error('mediaLibrary favorite failed with error: ' + error);
+ } else {
+ console.info('mediaLibrary favorite Successful');
+ }
});
+ fetchFileResult.close();
}
```
@@ -1566,18 +1593,18 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
- asset.favorite(true).then(function() {
- console.info("favorite successfully");
- }).catch(function(err){
- console.error("favorite failed with error: " + err);
+ asset.favorite(true).then(() => {
+ console.info('mediaLibrary favorite Successful');
+ }).catch((error) => {
+ console.error('mediaLibrary favorite failed with error: ' + error);
});
+ fetchFileResult.close();
}
```
@@ -1604,20 +1631,20 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
- asset.isFavorite((err, isFavorite) => {
- if (isFavorite) {
- console.info('FileAsset is favorite');
- }else{
- console.info('FileAsset is not favorite');
+ asset.isFavorite((error, isFavorite) => {
+ if (error) {
+ console.error('mediaLibrary favoriisFavoritete failed with error: ' + error);
+ } else {
+ console.info('mediaLibrary isFavorite Successful, isFavorite result: ' + isFavorite);
}
});
+ fetchFileResult.close();
}
```
@@ -1644,18 +1671,18 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
- asset.isFavorite().then(function(isFavorite){
- console.info("isFavorite result:"+ isFavorite);
- }).catch(function(err){
- console.error("isFavorite failed with error: " + err);
+ asset.isFavorite().then((isFavorite) => {
+ console.info('mediaLibrary isFavorite Successful, isFavorite result: ' + isFavorite);
+ }).catch((error) => {
+ console.error('mediaLibrary favoriisFavoritete failed with error: ' + error);
});
+ fetchFileResult.close();
}
```
@@ -1685,17 +1712,20 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
- asset.trash(true, trashCallBack);
- function trashCallBack(err, trash) {
- console.info('mediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK trash');
- }
+ asset.trash(true, (error) => {
+ if (error) {
+ console.error('mediaLibrary trash failed with error: ' + error);
+ } else {
+ console.info('mediaLibrary trash Successful');
+ }
+ });
+ fetchFileResult.close();
}
```
@@ -1730,18 +1760,18 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
- asset.trash(true).then(function() {
- console.info("trash successfully");
- }).catch(function(err){
- console.error("trash failed with error: " + err);
+ asset.trash(true).then(() => {
+ console.info('trash successfully');
+ }).catch((error) => {
+ console.error('trash failed with error: ' + error);
});
+ fetchFileResult.close();
}
```
@@ -1768,20 +1798,20 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
- asset.isTrash((err, isTrash) => {
- if (isTrash == undefined) {
- console.error('Failed to get trash state: ' + err);
- return;
- }
- console.info('Get trash state success: ' + isTrash);
+ asset.isTrash((error, isTrash) => {
+ if (error) {
+ console.error('Failed to get trash state failed with error: ' + error);
+ return;
+ }
+ console.info('Get trash state successfully, isTrash result: ' + isTrash);
});
+ fetchFileResult.close();
}
```
@@ -1808,17 +1838,18 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
- asset.isTrash().then(function(isTrash){
- console.info("isTrash result: " + isTrash);
- }).catch(function(err){
- console.error("isTrash failed with error: " + err);
+ asset.isTrash().then((isTrash) => {
+ console.info('isTrash result: ' + isTrash);
+ }).catch((error) => {
+ console.error('isTrash failed with error: ' + error);
});
+ fetchFileResult.close();
}
```
@@ -1849,11 +1880,12 @@ async function example() {
let getFileCountOneOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [fileType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getFileCountOneOp);
const fetchCount = fetchFileResult.getCount();
+ console.info('fetchCount result: ' + fetchCount);
+ fetchFileResult.close();
}
```
@@ -1878,25 +1910,22 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
const fetchCount = fetchFileResult.getCount();
- console.info('mediaLibraryTest : count:' + fetchCount);
+ console.info('mediaLibrary fetchFileResult.getCount, count:' + fetchCount);
let fileAsset = await fetchFileResult.getFirstObject();
for (var i = 1; i < fetchCount; i++) {
- fileAsset = await fetchFileResult.getNextObject();
- if(i == fetchCount - 1) {
- console.info('mediaLibraryTest : isLast');
- var result = fetchFileResult.isAfterLast();
- console.info('mediaLibraryTest : isAfterLast:' + result);
- console.info('mediaLibraryTest : isAfterLast end');
- fetchFileResult.close();
- }
+ fileAsset = await fetchFileResult.getNextObject();
+ if(i == fetchCount - 1) {
+ var result = fetchFileResult.isAfterLast();
+ console.info('mediaLibrary fileAsset isAfterLast result: ' + result);
+ }
}
+ fetchFileResult.close();
}
```
@@ -1915,10 +1944,9 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.close();
@@ -1946,19 +1974,19 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
- fetchFileResult.getFirstObject((err, fileAsset) => {
- if (err) {
- console.error('Failed ');
- return;
- }
- console.info('fileAsset.displayName : ' + fileAsset.displayName);
+ fetchFileResult.getFirstObject((error, fileAsset) => {
+ if (error) {
+ console.error('fetchFileResult getFirstObject failed with error: ' + error);
+ return;
+ }
+ console.info('getFirstObject successfully, displayName : ' + fileAsset.displayName);
})
+ fetchFileResult.close();
}
```
@@ -1983,17 +2011,17 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
- fetchFileResult.getFirstObject().then(function(fileAsset){
- console.info("getFirstObject successfully:"+ JSON.stringify(fileAsset));
- }).catch(function(err){
- console.error("getFirstObject failed with error: " + err);
+ fetchFileResult.getFirstObject().then((fileAsset) => {
+ console.info('getFirstObject successfully, displayName: ' + fileAsset.displayName);
+ }).catch((error) => {
+ console.error('getFirstObject failed with error: ' + error);
});
+ fetchFileResult.close();
}
```
@@ -2002,6 +2030,9 @@ async function example() {
getNextObject(callback: AsyncCallback<FileAsset>): void
Obtains the next file asset in the result set. This API uses an asynchronous callback to return the result.
+> **NOTE**
+>
+> Before using this API, you must use [getFirstObject](#getfirstobject7) to obtain the first file asset and then use [isAfterLast](#isafterlast7) to ensure that the cursor does not point to the last file asset in the result set.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
@@ -2018,20 +2049,24 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
- fetchFileResult.getNextObject((err, fileAsset) => {
- if (err) {
- console.error('Failed ');
- return;
- }
- console.log('fileAsset.displayName : ' + fileAsset.displayName);
- })
+ let fileAsset = await fetchFileResult.getFirstObject();
+ if (! fetchFileResult.isAfterLast) {
+ fetchFileResult.getNextObject((error, fileAsset) => {
+ if (error) {
+ console.error('fetchFileResult getNextObject failed with error: ' + error);
+ return;
+ }
+ console.log('fetchFileResult getNextObject successfully, displayName: ' + fileAsset.displayName);
+ })
+ }
+ fetchFileResult.close();
}
+
```
### getNextObject7+
@@ -2039,6 +2074,9 @@ async function example() {
getNextObject(): Promise<FileAsset>
Obtains the next file asset in the result set. This API uses a promise to return the result.
+> **NOTE**
+>
+> Before using this API, you must use [getFirstObject](#getfirstobject7) to obtain the first file asset and then use [isAfterLast](#isafterlast7) to ensure that the cursor does not point to the last file asset in the result set.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
@@ -2055,15 +2093,20 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
- const fetchCount = fetchFileResult.getCount();
- console.info('mediaLibraryTest : count:' + fetchCount);
- let fileAsset = await fetchFileResult.getNextObject();
+ let fileAsset = await fetchFileResult.getFirstObject();
+ if (! fetchFileResult.isAfterLast) {
+ fetchFileResult.getNextObject().then((fileAsset) => {
+ console.info('fetchFileResult getNextObject successfully, displayName: ' + fileAsset.displayName);
+ }).catch((error) => {
+ console.error('fetchFileResult getNextObject failed with error: ' + error);
+ })
+ }
+ fetchFileResult.close();
}
```
@@ -2088,19 +2131,19 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
- fetchFileResult.getLastObject((err, fileAsset) => {
- if (err) {
- console.error('Failed ');
- return;
- }
- console.info('fileAsset.displayName : ' + fileAsset.displayName);
+ fetchFileResult.getLastObject((error, fileAsset) => {
+ if (error) {
+ console.error('getLastObject failed with error: ' + error);
+ return;
+ }
+ console.info('getLastObject successfully, displayName: ' + fileAsset.displayName);
})
+ fetchFileResult.close();
}
```
@@ -2125,13 +2168,17 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
- let lastObject = await fetchFileResult.getLastObject();
+ fetchFileResult.getLastObject().then((fileAsset) => {
+ console.info('getLastObject successfully, displayName: ' + fileAsset.displayName);
+ }).catch((error) => {
+ console.error('getLastObject failed with error: ' + error);
+ });
+ fetchFileResult.close();
}
```
@@ -2147,7 +2194,7 @@ Obtains a file asset with the specified index in the result set. This API uses a
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------ |
-| index | number | Yes | Index of the file asset to obtain. The value starts from **0**. |
+| index | number | Yes | Index of the file to obtain. The value starts from 0 and must be smaller than the **count** value of the result set. |
| callback | AsyncCallback<[FileAsset](#fileasset7)> | Yes | Callback used to return the last file asset.|
**Example**
@@ -2157,19 +2204,19 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
- fetchFileResult.getPositionObject(0, (err, fileAsset) => {
- if (err) {
- console.error('Failed ');
- return;
- }
- console.info('fileAsset.displayName : ' + fileAsset.displayName);
+ fetchFileResult.getPositionObject(0, (error, fileAsset) => {
+ if (error) {
+ console.error('getPositionObject failed with error: ' + error);
+ return;
+ }
+ console.info('getPositionObject successfully, displayName: ' + fileAsset.displayName);
})
+ fetchFileResult.close();
}
```
@@ -2185,7 +2232,7 @@ Obtains a file asset with the specified index in the result set. This API uses a
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | -------------- |
-| index | number | Yes | Index of the file asset to obtain. The value starts from **0**.|
+| index | number | Yes | Index of the file to obtain. The value starts from 0 and must be smaller than the **count** value of the result set.|
**Return value**
@@ -2200,17 +2247,17 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
- fetchFileResult.getPositionObject(1) .then(function (fileAsset){
- console.info('fileAsset.displayName : ' + fileAsset.displayName);
- }).catch(function (err) {
- console.error("getFileAssets failed with error: " + err);
+ fetchFileResult.getPositionObject(0).then((fileAsset) => {
+ console.info('getPositionObject successfully, displayName: ' + fileAsset.displayName);
+ }).catch((error) => {
+ console.error('getPositionObject failed with error: ' + error);
});
+ fetchFileResult.close();
}
```
@@ -2226,7 +2273,7 @@ Obtains all the file assets in the result set. This API uses an asynchronous cal
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | -------------------- |
-| callback | AsyncCallback> | Yes | Callback used to return the file assets.|
+| callback | AsyncCallback<Array<[FileAsset](#fileasset7)>> | Yes | Callback used to return the file assets.|
**Example**
@@ -2235,21 +2282,21 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
- fetchFileResult.getAllObject((err, fileAsset) => {
- if (err) {
- console.error('Failed ');
+ fetchFileResult.getAllObject((error, fileAssetList) => {
+ if (error) {
+ console.error('getAllObject failed with error: ' + error);
return;
}
for (let i = 0; i < fetchFileResult.getCount(); i++) {
- console.info('fileAsset.displayName : ' + fileAsset[i].displayName);
+ console.info('getAllObject fileAssetList ' + i + ' displayName: ' + fileAssetList[i].displayName);
}
})
+ fetchFileResult.close();
}
```
@@ -2265,7 +2312,7 @@ Obtains all the file assets in the result set. This API uses a promise to return
| Type | Description |
| ---------------------------------------- | --------------------- |
-| Promise> | Promise used to return the file assets.|
+| Promise<Array<[FileAsset](#fileasset7)>> | Promise used to return the file assets.|
**Example**
@@ -2274,13 +2321,19 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
- selections: fileKeyObj.MEDIA_TYPE + '= ?',
- selectionArgs: [imageType.toString()],
- order: fileKeyObj.DATE_ADDED + " DESC",
- extendArgs: "",
+ selections: fileKeyObj.MEDIA_TYPE + '= ?',
+ selectionArgs: [imageType.toString()],
+ order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
- var data = fetchFileResult.getAllObject();
+ fetchFileResult.getAllObject().then((fileAssetList) => {
+ for (let i = 0; i < fetchFileResult.getCount(); i++) {
+ console.info('getAllObject fileAssetList ' + i + ' displayName: ' + fileAssetList[i].displayName);
+ }
+ }).catch((error) => {
+ console.error('getAllObject failed with error: ' + error);
+ });
+ fetchFileResult.close();
}
```
@@ -2329,12 +2382,12 @@ async function example() {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
album.albumName = 'hello';
- album.commitModify((err) => {
- if (err) {
- console.error('Failed ');
- return;
- }
- console.info('Modify successful.');
+ album.commitModify((error) => {
+ if (error) {
+ console.error('commitModify failed with error: ' + error);
+ return;
+ }
+ console.info('commitModify successful.');
})
}
```
@@ -2366,10 +2419,10 @@ async function example() {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
album.albumName = 'hello';
- album.commitModify().then(function() {
- console.info("commitModify successfully");
- }).catch(function(err){
- console.error("commitModify failed with error: " + err);
+ album.commitModify().then(() => {
+ console.info('commitModify successfully');
+ }).catch((error) => {
+ console.error('commitModify failed with error: ' + error);
});
}
```
@@ -2400,15 +2453,22 @@ async function example() {
selectionArgs: [],
};
let fileNoArgsfetchOp = {
- selections: '',
- selectionArgs: [],
+ selections: '',
+ selectionArgs: [],
}
+ // Obtain the albums that meet the retrieval options and return the album list.
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
- album.getFileAssets(fileNoArgsfetchOp, getFileAssetsCallBack);
- function getFileAssetsCallBack(err, fetchFileResult) {
- // do something
- }
+ // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album.
+ album.getFileAssets(fileNoArgsfetchOp, (error, fetchFileResult) => {
+ if (error) {
+ console.error('album getFileAssets failed with error: ' + error);
+ return;
+ }
+ let count = fetchFileResult.getcount();
+ console.info('album getFileAssets successfully, count: ' + count);
+ });
+ fetchFileResult.close();
}
```
@@ -2442,17 +2502,21 @@ async function example() {
selections: '',
selectionArgs: [],
};
- let fileNoArgsfetchOp = {
- selections: '',
- selectionArgs: [],
+ let fileNoArgsfetchOp = {
+ selections: '',
+ selectionArgs: [],
};
+ // Obtain the albums that meet the retrieval options and return the album list.
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
- album.getFileAssets(fileNoArgsfetchOp).then(function(albumFetchFileResult){
- console.info("getFileAssets successfully: " + JSON.stringify(albumFetchFileResult));
- }).catch(function(err){
- console.error("getFileAssets failed with error: " + err);
+ // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album.
+ album.getFileAssets(fileNoArgsfetchOp).then((albumFetchFileResult) => {
+ let count = fetchFileResult.getcount();
+ console.info('album getFileAssets successfully, count: ' + count);
+ }).catch((error) => {
+ console.error('album getFileAssets failed with error: ' + error);
});
+ fetchFileResult.close();
}
```
@@ -2491,32 +2555,32 @@ Enumerates media types.
Enumerates key file information.
> **NOTE**
->
+>
> The **bucket_id** field may change after file rename or movement. Therefore, you must obtain the field again before using it.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
| Name | Value | Description |
| ------------- | ------------------- | ---------------------------------------------------------- |
-| ID | "file_id" | File ID. |
-| RELATIVE_PATH | "relative_path" | Relative public directory of the file. |
-| DISPLAY_NAME | "display_name" | Display file name. |
-| PARENT | "parent" | Parent directory ID. |
-| MIME_TYPE | "mime_type" | Extended file attributes. |
-| MEDIA_TYPE | "media_type" | Media type. |
-| SIZE | "size" | File size, in bytes. |
-| DATE_ADDED | "date_added" | Date when the file was added. The value is the number of seconds elapsed since the Epoch time. |
-| DATE_MODIFIED | "date_modified" | Date when the file content (not the file name) was last modified. The value is the number of seconds elapsed since the Epoch time.|
-| DATE_TAKEN | "date_taken" | Date when the file (photo) was taken. The value is the number of seconds elapsed since the Epoch time. |
-| TITLE | "title" | Title in the file. |
-| ARTIST | "artist" | Artist of the file. |
-| AUDIOALBUM | "audio_album" | Audio album. |
-| DURATION | "duration" | Duration, in ms. |
-| WIDTH | "width" | Image width, in pixels. |
-| HEIGHT | "height" | Image height, in pixels. |
-| ORIENTATION | "orientation" | Image display direction (clockwise rotation angle, for example, 0, 90, and 180, in degrees).|
-| ALBUM_ID | "bucket_id" | ID of the album to which the file belongs. |
-| ALBUM_NAME | "bucket_display_name" | Name of the album to which the file belongs. |
+| ID | 'file_id' | File ID. |
+| RELATIVE_PATH | 'relative_path' | Relative public directory of the file. |
+| DISPLAY_NAME | 'display_name' | Display file name. |
+| PARENT | 'parent' | Parent directory ID. |
+| MIME_TYPE | 'mime_type' | Extended file attributes, such as image/, video/, and file/*. |
+| MEDIA_TYPE | 'media_type' | Media type. |
+| SIZE | 'size' | File size, in bytes. |
+| DATE_ADDED | 'date_added' | Date when the file was added. The value is the number of seconds elapsed since the Epoch time. |
+| DATE_MODIFIED | 'date_modified' | Date when the file content (not the file name) was last modified. The value is the number of seconds elapsed since the Epoch time.|
+| DATE_TAKEN | 'date_taken' | Date when the file (photo) was taken. The value is the number of seconds elapsed since the Epoch time. |
+| TITLE | 'title' | Title in the file. |
+| ARTIST | 'artist' | Artist of the file. |
+| AUDIOALBUM | 'audio_album' | Audio album. |
+| DURATION | 'duration' | Duration, in ms. |
+| WIDTH | 'width' | Image width, in pixels. |
+| HEIGHT | 'height' | Image height, in pixels. |
+| ORIENTATION | 'orientation' | Image display direction (clockwise rotation angle, for example, 0, 90, and 180, in degrees).|
+| ALBUM_ID | 'bucket_id' | ID of the album to which the file belongs. |
+| ALBUM_NAME | 'bucket_display_name' | Name of the album to which the file belongs. |
## DirectoryType8+
@@ -2559,9 +2623,9 @@ Describes options for fetching media files.
| Name | Type | Readable| Writable| Description |
| ----------------------- | ------------------- | ---- | ---- | ------------------------------------------------------------ |
-| selections | string | Yes | Yes | Conditions for fetching files. The enumerated values in [FileKey](#filekey8) are used as the column names of the conditions. Example:
selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ? OR ' +mediaLibrary.FileKey.MEDIA_TYPE + '= ?', |
+| selections | string | Yes | Yes | Conditions for fetching files. The enumerated values in [FileKey](#filekey8) are used as the column names of the conditions. Example:
selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ? OR ' + mediaLibrary.FileKey.MEDIA_TYPE + '= ?', |
| selectionArgs | Array<string> | Yes | Yes | Value of the condition, which corresponds to the value of the condition column in **selections**.
Example:
selectionArgs: [mediaLibrary.MediaType.IMAGE.toString(), mediaLibrary.MediaType.VIDEO.toString()], |
-| order | string | Yes | Yes | Sorting mode of the search results, which can be ascending or descending. The enumerated values in [FileKey](#filekey8) are used as the columns for sorting the search results. Example:
Ascending: order: mediaLibrary.FileKey.DATE_ADDED + " ASC"
Descending: order: mediaLibrary.FileKey.DATE_ADDED + " DESC"|
+| order | string | Yes | Yes | Sorting mode of the search results, which can be ascending or descending. The enumerated values in [FileKey](#filekey8) are used as the columns for sorting the search results. Example:
Ascending: order: mediaLibrary.FileKey.DATE_ADDED + ' ASC'
Descending: order: mediaLibrary.FileKey.DATE_ADDED + ' DESC'|
| uri8+ | string | Yes | Yes | File URI. |
| networkId8+ | string | Yes | Yes | Network ID of the registered device. |
| extendArgs8+ | string | Yes | Yes | Extended parameters for fetching the files. Currently, no extended parameters are available. |
diff --git a/en/application-dev/reference/apis/js-apis-reminderAgentManager.md b/en/application-dev/reference/apis/js-apis-reminderAgentManager.md
index f443c028e40072e8b402f93b54be1e9ecfdc0842..7d56973be54adf176ce6c22519cb125079f19df3 100644
--- a/en/application-dev/reference/apis/js-apis-reminderAgentManager.md
+++ b/en/application-dev/reference/apis/js-apis-reminderAgentManager.md
@@ -1,4 +1,4 @@
-# @ohos.reminderAgentManager (Reminder Agent Management)
+# @ohos.reminderAgentManager (reminderAgentManager)
The **reminderAgentManager** module provides APIs for publishing scheduled reminders through the reminder agent.
@@ -696,8 +696,8 @@ Sets the time information for a calendar reminder.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| year | number | Yes| Year.|
-| month | number | Yes| Month.|
-| day | number | Yes| Date.|
-| hour | number | Yes| Hour.|
-| minute | number | Yes| Minute.|
-| second | number | No| Second.|
+| month | number | Yes| Month. The value ranges from 1 to 12.|
+| day | number | Yes| Day. The value ranges from 1 to 31.|
+| hour | number | Yes| Hour. The value ranges from 0 to 23.|
+| minute | number | Yes| Minute. The value ranges from 0 to 59.|
+| second | number | No| Second. The value ranges from 0 to 59.|
diff --git a/en/application-dev/reference/apis/js-apis-util.md b/en/application-dev/reference/apis/js-apis-util.md
index 21ac9df11df7cabdf260edf97fc5fe17f83871b8..ea60b649da3f2d73dfb9cba42dab8ccdee16cde0 100755
--- a/en/application-dev/reference/apis/js-apis-util.md
+++ b/en/application-dev/reference/apis/js-apis-util.md
@@ -26,7 +26,7 @@ Formats the specified values and inserts them into the string by replacing the w
| Name | Type | Mandatory| Description |
| ------- | -------- | ---- | -------------- |
| format | string | Yes | String.|
-| ...args | Object[] | No | Values to format. The formatted values will be replaced the wildcard in the string. |
+| ...args | Object[] | No | Values to format. The formatted values will replace the wildcard in the string. If this parameter is not set, the first parameter is returned by default.|
**Return value**
@@ -69,6 +69,20 @@ let result = util.errnoToString(errnum);
console.log("result = " + result);
```
+**Some error code and message examples**
+
+| Error Code| Message |
+| ------ | -------------------------------- |
+| -1 | operation not permitted |
+| -2 | no such file or directory |
+| -3 | no such process |
+| -4 | interrupted system call |
+| -5 | i/o error |
+| -11 | resource temporarily unavailable |
+| -12 | not enough memory |
+| -13 | permission denied |
+| -100 | network is down |
+
## util.callbackWrapper
callbackWrapper(original: Function): (err: Object, value: Object )=>void
@@ -92,15 +106,14 @@ Calls back an asynchronous function. In the callback, the first parameter indica
**Example**
```js
- async function promiseFn() {
- return Promise.reject('value');
- }
- let err = "type err";
- let cb = util.callbackWrapper(promiseFn);
- cb((err, ret) => {
- console.log(err);
- console.log(ret);
- }, err)
+async function fn() {
+ return 'hello world';
+}
+let cb = util.callbackWrapper(fn);
+cb((err, ret) => {
+ if (err) throw err;
+ console.log(ret);
+});
```
## util.promisify9+
@@ -126,24 +139,30 @@ Processes an asynchronous function and returns a promise.
**Example**
```js
- function aysnFun(str1, str2) {
- if (typeof str1 === 'object' && typeof str2 === 'object') {
- return str2
- } else {
- return str1
- }
- }
- let newPromiseObj = util.promisify(aysnFun);
- newPromiseObj({ err: "type error" }, {value:'HelloWorld'}).then(res => {
- console.log(res);
- })
+function fun(num, callback) {
+ if (typeof num === 'number') {
+ callback(null, num + 3);
+ } else {
+ callback("type err");
+ }
+}
+
+const addCall = util.promisify(fun);
+(async () => {
+ try {
+ let res = await addCall(2);
+ console.log(res);
+ } catch (err) {
+ console.log(err);
+ }
+})();
```
-## util.randomUUID9+
+## util.generateRandomUUID9+
-randomUUID(entropyCache?: boolean): string
+generateRandomUUID(entropyCache?: boolean): string
-Uses a secure random number generator to generate a random universally unique identifier (UUID) of RFC 4122 version 4.
+Uses a secure random number generator to generate a random universally unique identifier (UUID) of the string type in RFC 4122 version 4.
**System capability**: SystemCapability.Utils.Lang
@@ -162,17 +181,17 @@ Uses a secure random number generator to generate a random universally unique id
**Example**
```js
- let uuid = util.randomUUID(true);
+ let uuid = util.generateRandomUUID(true);
console.log("RFC 4122 Version 4 UUID:" + uuid);
// Output:
// RFC 4122 Version 4 UUID:88368f2a-d5db-47d8-a05f-534fab0a0045
```
-## util.randomBinaryUUID9+
+## util.generateRandomBinaryUUID9+
-randomBinaryUUID(entropyCache?: boolean): Uint8Array
+generateRandomBinaryUUID(entropyCache?: boolean): Uint8Array
-Uses a secure random number generator to generate a random binary UUID of RFC 4122 version 4.
+Uses a secure random number generator to generate a random UUID of the Uint8Array type in RFC 4122 version 4.
**System capability**: SystemCapability.Utils.Lang
@@ -191,7 +210,7 @@ Uses a secure random number generator to generate a random binary UUID of RFC 41
**Example**
```js
- let uuid = util.randomBinaryUUID(true);
+ let uuid = util.generateRandomBinaryUUID(true);
console.log(JSON.stringify(uuid));
// Output:
// 138,188,43,243,62,254,70,119,130,20,235,222,199,164,140,150
@@ -201,7 +220,7 @@ Uses a secure random number generator to generate a random binary UUID of RFC 41
parseUUID(uuid: string): Uint8Array
-Parses a UUID from a string, as described in RFC 4122 version 4.
+Converts the UUID of the string type generated by **generateRandomUUID** to the UUID of the **Uint8Array** type generated by **generateRandomBinaryUUID**, as described in RFC 4122 version 4.
**System capability**: SystemCapability.Utils.Lang
@@ -243,7 +262,7 @@ Formats the specified values and inserts them into the string by replacing the w
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| format | string | Yes| String.|
-| ...args | Object[] | No| Values to format. The formatted values will be replaced the wildcard in the string.|
+| ...args | Object[] | No| Values to format. The formatted values will replace the wildcard in the string. If this parameter is not set, the first parameter is returned by default.|
**Return value**
@@ -361,8 +380,8 @@ Creates a **TextDecoder** object. It provides the same function as the deprecate
**Example**
```js
-let textDecoder = new util.TextDecoder()
-textDecoder.create('utf-8', { ignoreBOM : true });
+let result = util.TextDecoder.create('utf-8', { ignoreBOM : true })
+let retStr = result.encoding
```
### decodeWithStream9+