提交 6f97472b 编写于 作者: G Gloria

Update docs against 14857+15063+15014

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 a20f8a88
...@@ -47,21 +47,27 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ...@@ -47,21 +47,27 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
**Example** **Example**
```js ```js
let xml = try {
'<?xml version="1.0" encoding="utf-8"?>' + let xml =
'<note importance="high" logged="true">' + '<?xml version="1.0" encoding="utf-8"?>' +
' <title>Happy</title>' + '<note importance="high" logged="true">' +
' <todo>Work</todo>' + ' <title>Happy</title>' +
' <todo>Play</todo>' + ' <todo>Work</todo>' +
'</note>'; ' <todo>Play</todo>' +
let conv = new convertxml.ConvertXML() '</note>';
let options = {trim : false, declarationKey:"_declaration", let conv = new convertxml.ConvertXML()
instructionKey : "_instruction", attributesKey : "_attributes", let options = {
textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype", trim: false, declarationKey: "_declaration",
commentKey : "_comment", parentKey : "_parent", typeKey : "_type", instructionKey: "_instruction", attributesKey: "_attributes",
nameKey : "_name", elementsKey : "_elements"} textKey: "_text", cdataKey: "_cdata", doctypeKey: "_doctype",
let result = JSON.stringify(conv.convertToJSObject(xml, options)); commentKey: "_comment", parentKey: "_parent", typeKey: "_type",
console.log(result); nameKey: "_name", elementsKey: "_elements"
}
let result = JSON.stringify(conv.convertToJSObject(xml, options));
console.log(result);
} catch (e) {
console.log(e.toString());
}
// Output (non-compact) // 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"}]}]}]} // {"_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"}]}]}]}
``` ```
......
...@@ -34,6 +34,7 @@ This API can be used only in the stage model. ...@@ -34,6 +34,7 @@ This API can be used only in the stage model.
**Example (from API version 9)** **Example (from API version 9)**
```ts ```ts
// Obtain a MediaLibrary instance. The instance obtained here is used in later.
const context = getContext(this); const context = getContext(this);
let media = mediaLibrary.getMediaLibrary(context); let media = mediaLibrary.getMediaLibrary(context);
``` ```
...@@ -92,46 +93,59 @@ Obtains file assets (also called files). This API uses an asynchronous callback ...@@ -92,46 +93,59 @@ Obtains file assets (also called files). This API uses an asynchronous callback
**Example** **Example**
```js ```js
let fileKeyObj = mediaLibrary.FileKey; async function example() {
let imageType = mediaLibrary.MediaType.IMAGE; let fileKeyObj = mediaLibrary.FileKey;
let imagesFetchOp = { let imageType = mediaLibrary.MediaType.IMAGE;
selections: fileKeyObj.MEDIA_TYPE + '= ?', // Create options for fetching the files. The options are used to obtain files of the image type.
selectionArgs: [imageType.toString()], let imagesFetchOp = {
}; selections: fileKeyObj.MEDIA_TYPE + '= ?',
media.getFileAssets(imagesFetchOp, (error, fetchFileResult) => { selectionArgs: [imageType.toString()],
if (fetchFileResult == undefined) { };
console.error('Failed to get fetchFileResult: ' + error); // Obtain the files in asynchronous callback mode.
return; media.getFileAssets(imagesFetchOp, (error, fetchFileResult) => {
} // Check whether the result set of the obtained files is undefined. If yes, the API call fails.
const count = fetchFileResult.getCount(); if (fetchFileResult == undefined) {
if (count < 0) { console.error('get fetchFileResult failed with error: ' + error);
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);
return; return;
} }
console.info('fileAsset.displayName ' + ': ' + fileAsset.displayName); // Obtain the total number of files in the result set.
for (let i = 1; i < count; i++) { const count = fetchFileResult.getCount();
fetchFileResult.getNextObject((err, fileAsset) => { // Check whether the number is less than 0. If yes, the API call fails.
if (fileAsset == undefined) { if (count < 0) {
console.error('Failed to get next object: ' + err); console.error('get count from fetchFileResult failed, count: ' + count);
return; return;
}
console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName);
})
} }
// 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();
}); });
}); }
``` ```
### getFileAssets<sup>7+</sup> ### getFileAssets<sup>7+</sup>
getFileAssets(options: MediaFetchOptions): Promise&lt;FetchFileResult&gt; getFileAssets(options: MediaFetchOptions): Promise&lt;FetchFileResult&gt;
...@@ -157,38 +171,51 @@ Obtains file assets. This API uses a promise to return the result. ...@@ -157,38 +171,51 @@ Obtains file assets. This API uses a promise to return the result.
**Example** **Example**
```js ```js
let fileKeyObj = mediaLibrary.FileKey; async function example() {
let imageType = mediaLibrary.MediaType.IMAGE; let fileKeyObj = mediaLibrary.FileKey;
let imagesFetchOp = { let imageType = mediaLibrary.MediaType.IMAGE;
selections: fileKeyObj.MEDIA_TYPE + '= ?', // Create options for fetching the files. The options are used to obtain files of the image type.
selectionArgs: [imageType.toString()], let imagesFetchOp = {
}; selections: fileKeyObj.MEDIA_TYPE + '= ?',
media.getFileAssets(imagesFetchOp).then(function(fetchFileResult) { selectionArgs: [imageType.toString()],
const count = fetchFileResult.getCount(); };
if (count < 0) { // Obtain the files in promise mode.
console.error('Failed to get count from fetchFileResult: count: ' + count); media.getFileAssets(imagesFetchOp).then((fetchFileResult) => {
return; // Obtain the total number of files in the result set.
} const count = fetchFileResult.getCount();
if (count == 0) { // Check whether the number is less than 0. If yes, the API call fails.
console.info('The count of fetchFileResult is zero'); if (count < 0) {
return; console.error('get count from fetchFileResult failed, count: ' + count);
} 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);
})
} }
}).catch(function(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.
console.error('Failed to get first object: ' + err); 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);
});
``` ```
### on<sup>8+</sup> ### on<sup>8+</sup>
...@@ -232,7 +259,7 @@ Unsubscribes from the media library changes. This API uses an asynchronous callb ...@@ -232,7 +259,7 @@ Unsubscribes from the media library changes. This API uses an asynchronous callb
```js ```js
media.off('imageChange', () => { media.off('imageChange', () => {
// stop listening success // Stop listening successfully.
}) })
``` ```
...@@ -263,11 +290,11 @@ async function example() { ...@@ -263,11 +290,11 @@ async function example() {
let mediaType = mediaLibrary.MediaType.IMAGE; let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(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) { if (fileAsset != undefined) {
console.info('createAsset successfully, message'); console.info('createAsset successfully, message');
} else { } else {
console.error('createAsset failed, message = ' + err); console.error('createAsset failed with error: ' + error);
} }
}); });
} }
...@@ -307,8 +334,8 @@ async function example() { ...@@ -307,8 +334,8 @@ async function example() {
const path = await media.getPublicDirectory(DIR_IMAGE); const path = await media.getPublicDirectory(DIR_IMAGE);
media.createAsset(mediaType, 'imagePromise.jpg', path + 'myPicture/').then((fileAsset) => { media.createAsset(mediaType, 'imagePromise.jpg', path + 'myPicture/').then((fileAsset) => {
console.info('createAsset successfully, message = ' + JSON.stringify(fileAsset)); console.info('createAsset successfully, message = ' + JSON.stringify(fileAsset));
}).catch((err) => { }).catch((error) => {
console.error('createAsset failed, message = ' + err); console.error('createAsset failed with error: ' + error);
}); });
} }
``` ```
...@@ -349,14 +376,15 @@ async function example() { ...@@ -349,14 +376,15 @@ async function example() {
const fetchFileResult = await media.getFileAssets(option); const fetchFileResult = await media.getFileAssets(option);
let asset = await fetchFileResult.getFirstObject(); let asset = await fetchFileResult.getFirstObject();
if (asset == undefined) { if (asset == undefined) {
console.error('asset not exist') console.error('asset not exist');
return return;
} }
media.deleteAsset(asset.uri).then(() => { media.deleteAsset(asset.uri).then(() => {
console.info("deleteAsset successfully"); console.info('deleteAsset successfully');
}).catch((err) => { }).catch((error) => {
console.error("deleteAsset failed with error:"+ err); console.error('deleteAsset failed with error: ' + error);
}); });
fetchFileResult.close();
} }
``` ```
...@@ -391,16 +419,17 @@ async function example() { ...@@ -391,16 +419,17 @@ async function example() {
const fetchFileResult = await media.getFileAssets(option); const fetchFileResult = await media.getFileAssets(option);
let asset = await fetchFileResult.getFirstObject(); let asset = await fetchFileResult.getFirstObject();
if (asset == undefined) { if (asset == undefined) {
console.error('asset not exist') console.error('asset not exist');
return return;
} }
media.deleteAsset(asset.uri, (err) => { media.deleteAsset(asset.uri, (error) => {
if (err != undefined) { if (error != undefined) {
console.info("deleteAsset successfully"); console.error('deleteAsset failed with error: ' + error);
} else { } 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 ...@@ -423,11 +452,11 @@ Obtains a public directory. This API uses an asynchronous callback to return the
```js ```js
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
media.getPublicDirectory(DIR_CAMERA, (err, dicResult) => { media.getPublicDirectory(DIR_CAMERA, (error, dicResult) => {
if (dicResult == 'Camera/') { if (dicResult == 'Camera/') {
console.info('mediaLibraryTest : getPublicDirectory passed'); console.info('getPublicDirectory DIR_CAMERA successfully');
} else { } 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. ...@@ -457,12 +486,15 @@ Obtains a public directory. This API uses a promise to return the result.
```js ```js
async function example() { async function example() {
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
const dicResult = await media.getPublicDirectory(DIR_CAMERA); media.getPublicDirectory(DIR_CAMERA).then((dicResult) => {
if (dicResult == 'Camera/') { if (dicResult == 'Camera/') {
console.info('MediaLibraryTest : getPublicDirectory'); console.info('getPublicDirectory DIR_CAMERA successfully');
} else { } else {
console.error('MediaLibraryTest : getPublicDirectory failed'); 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. ...@@ -486,19 +518,19 @@ Obtains the albums. This API uses an asynchronous callback to return the result.
**Example** **Example**
```js ```js
let AlbumNoArgsfetchOp = { async function example() {
selections: '', let AlbumNoArgsfetchOp = {
selectionArgs: [], selections: '',
}; selectionArgs: [],
media.getAlbums(AlbumNoArgsfetchOp, (err, albumList) => { };
if (albumList != undefined) { media.getAlbums(AlbumNoArgsfetchOp, (error, albumList) => {
const album = albumList[0]; if (albumList != undefined) {
console.info('album.albumName = ' + album.albumName); console.info('getAlbums successfully: ' + JSON.stringify(albumList));
console.info('album.count = ' + album.count); } else {
} else { console.error('getAlbums failed with error: ' + error);
console.error('getAlbum fail, message = ' + err); }
} })
}) }
``` ```
### getAlbums<sup>7+</sup> ### getAlbums<sup>7+</sup>
...@@ -526,15 +558,17 @@ Obtains the albums. This API uses a promise to return the result. ...@@ -526,15 +558,17 @@ Obtains the albums. This API uses a promise to return the result.
**Example** **Example**
```js ```js
let AlbumNoArgsfetchOp = { async function example() {
selections: '', let AlbumNoArgsfetchOp = {
selectionArgs: [], selections: '',
}; selectionArgs: [],
media.getAlbums(AlbumNoArgsfetchOp).then(function(albumList){ };
console.info("getAlbums successfully:"+ JSON.stringify(albumList)); media.getAlbums(AlbumNoArgsfetchOp).then((albumList) => {
}).catch(function(err){ console.info('getAlbums successfully: ' + JSON.stringify(albumList));
console.error("getAlbums failed with error: " + err); }).catch((error) => {
}); console.error('getAlbums failed with error: ' + error);
});
}
``` ```
### release<sup>8+</sup> ### release<sup>8+</sup>
...@@ -550,12 +584,12 @@ Call this API when you no longer need to use the APIs in the **MediaLibrary** in ...@@ -550,12 +584,12 @@ Call this API when you no longer need to use the APIs in the **MediaLibrary** in
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------- | | -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the execution result.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
**Example** **Example**
```js ```js
media.release((err) => { media.release(() => {
// do something // do something
}); });
``` ```
...@@ -604,16 +638,16 @@ Stores a media asset. This API uses an asynchronous callback to return the URI t ...@@ -604,16 +638,16 @@ Stores a media asset. This API uses an asynchronous callback to return the URI t
```js ```js
let option = { let option = {
src : "/data/storage/el2/base/haps/entry/image.png", src : '/data/storage/el2/base/haps/entry/image.png',
mimeType : "image/*", mimeType : 'image/*',
relativePath : "Pictures/" relativePath : 'Pictures/'
}; };
mediaLibrary.getMediaLibrary().storeMediaAsset(option, (err, value) => { mediaLibrary.getMediaLibrary().storeMediaAsset(option, (error, value) => {
if (err) { if (error) {
console.error("An error occurred when storing media resources."); console.error('storeMediaAsset failed with error: ' + error);
return; return;
} }
console.info("Media resources stored. "); console.info('Media resources stored. ');
// Obtain the URI that stores the media asset. // 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 ...@@ -647,15 +681,15 @@ Stores a media asset. This API uses a promise to return the URI that stores the
```js ```js
let option = { let option = {
src : "/data/storage/el2/base/haps/entry/image.png", src : '/data/storage/el2/base/haps/entry/image.png',
mimeType : "image/*", mimeType : 'image/*',
relativePath : "Pictures/" relativePath : 'Pictures/'
}; };
mediaLibrary.getMediaLibrary().storeMediaAsset(option).then((value) => { mediaLibrary.getMediaLibrary().storeMediaAsset(option).then((value) => {
console.info("Media resources stored."); console.info('Media resources stored.');
// Obtain the URI that stores the media asset. // Obtain the URI that stores the media asset.
}).catch((err) => { }).catch((error) => {
console.error("An error occurred when storing media resources."); 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 ...@@ -676,7 +710,7 @@ Starts image preview, with the first image to preview specified. This API can be
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------- | ---- | ---------------------------------------- |
| images | Array&lt;string&gt; | Yes | URIs of the images to preview. The value can start with either **https://** or **datashare://**.| | images | Array&lt;string&gt; | 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. | | index | number | Yes | Index of the first image to preview. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the image preview result. If the preview fails, an error message is returned. | | callback | AsyncCallback&lt;void&gt; | 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 ...@@ -684,22 +718,22 @@ Starts image preview, with the first image to preview specified. This API can be
```js ```js
let images = [ let images = [
"datashare:///media/xxxx/2", 'datashare:///media/xxxx/2',
"datashare:///media/xxxx/3" 'datashare:///media/xxxx/3'
]; ];
/* Preview online images. /* Preview online images.
let images = [ let images = [
"https://media.xxxx.com/image1.jpg", 'https://media.xxxx.com/image1.jpg',
"https://media.xxxx.com/image2.jpg" 'https://media.xxxx.com/image2.jpg'
]; ];
*/ */
let index = 1; let index = 1;
mediaLibrary.getMediaLibrary().startImagePreview(images, index, (err) => { mediaLibrary.getMediaLibrary().startImagePreview(images, index, (error) => {
if (err) { if (error) {
console.error("An error occurred when previewing the images."); console.error('startImagePreview failed with error: ' + error);
return; 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 ...@@ -720,28 +754,28 @@ Starts image preview. This API can be used to preview local images whose URIs st
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------- | ---- | ---------------------------------------- |
| images | Array&lt;string&gt; | Yes | URIs of the images to preview. The value can start with either **https://** or **datashare://**.| | images | Array&lt;string&gt; | Yes | URIs of the images to preview. The value can start with either **'https://'** or **'datashare://'**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the image preview result. If the preview fails, an error message is returned. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the image preview result. If the preview fails, an error message is returned. |
**Example** **Example**
```js ```js
let images = [ let images = [
"datashare:///media/xxxx/2", 'datashare:///media/xxxx/2',
"datashare:///media/xxxx/3" 'datashare:///media/xxxx/3'
]; ];
/* Preview online images. /* Preview online images.
let images = [ let images = [
"https://media.xxxx.com/image1.jpg", 'https://media.xxxx.com/image1.jpg',
"https://media.xxxx.com/image2.jpg" 'https://media.xxxx.com/image2.jpg'
]; ];
*/ */
mediaLibrary.getMediaLibrary().startImagePreview(images, (err) => { mediaLibrary.getMediaLibrary().startImagePreview(images, (error) => {
if (err) { if (error) {
console.error("An error occurred when previewing the images."); console.error('startImagePreview failed with error: ' + error);
return; 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 ...@@ -762,7 +796,7 @@ Starts image preview, with the first image to preview specified. This API can be
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------------------- | ---- | ---------------------------------------- | | ------ | ------------------- | ---- | ---------------------------------------- |
| images | Array&lt;string&gt; | Yes | URIs of the images to preview. The value can start with either **https://** or **datashare://**.| | images | Array&lt;string&gt; | 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. | | index | number | No | Index of the first image to preview. If this parameter is not specified, the default value **0** is used. |
**Return value** **Return value**
...@@ -775,20 +809,20 @@ Starts image preview, with the first image to preview specified. This API can be ...@@ -775,20 +809,20 @@ Starts image preview, with the first image to preview specified. This API can be
```js ```js
let images = [ let images = [
"datashare:///media/xxxx/2", 'datashare:///media/xxxx/2',
"datashare:///media/xxxx/3" 'datashare:///media/xxxx/3'
]; ];
/* Preview online images. /* Preview online images.
let images = [ let images = [
"https://media.xxxx.com/image1.jpg", 'https://media.xxxx.com/image1.jpg',
"https://media.xxxx.com/image2.jpg" 'https://media.xxxx.com/image2.jpg'
]; ];
*/ */
let index = 1; let index = 1;
mediaLibrary.getMediaLibrary().startImagePreview(images, index).then(() => { mediaLibrary.getMediaLibrary().startImagePreview(images, index).then(() => {
console.info("Succeeded in previewing the images."); console.info('Succeeded in previewing the images.');
}).catch((err) => { }).catch((error) => {
console.error("An error occurred when previewing the images."); console.error('startImagePreview failed with error: ' + error);
}); });
``` ```
...@@ -816,15 +850,15 @@ Starts media selection. This API uses an asynchronous callback to return the lis ...@@ -816,15 +850,15 @@ Starts media selection. This API uses an asynchronous callback to return the lis
```js ```js
let option : mediaLibrary.MediaSelectOption = { let option : mediaLibrary.MediaSelectOption = {
type : "media", type : 'media',
count : 2 count : 2
}; };
mediaLibrary.getMediaLibrary().startMediaSelect(option, (err, value) => { mediaLibrary.getMediaLibrary().startMediaSelect(option, (error, value) => {
if (err) { if (error) {
console.error("An error occurred when selecting media resources."); console.error('startMediaSelect failed with error: ' + error);
return; return;
} }
console.info("Media resources selected."); console.info('Media resources selected.');
// Obtain the media selection value. // Obtain the media selection value.
}); });
``` ```
...@@ -858,14 +892,14 @@ Starts media selection. This API uses a promise to return the list of URIs that ...@@ -858,14 +892,14 @@ Starts media selection. This API uses a promise to return the list of URIs that
```js ```js
let option : mediaLibrary.MediaSelectOption = { let option : mediaLibrary.MediaSelectOption = {
type : "media", type : 'media',
count : 2 count : 2
}; };
mediaLibrary.getMediaLibrary().startMediaSelect(option).then((value) => { mediaLibrary.getMediaLibrary().startMediaSelect(option).then((value) => {
console.info("Media resources selected."); console.info('Media resources selected.');
// Obtain the media selection value. // Obtain the media selection value.
}).catch((err) => { }).catch((error) => {
console.error("An error occurred when selecting media resources."); console.error('startMediaSelect failed with error: ' + error);
}); });
``` ```
...@@ -893,14 +927,12 @@ Obtains information about online peer devices. This API uses a promise to return ...@@ -893,14 +927,12 @@ Obtains information about online peer devices. This API uses a promise to return
async function example() { async function example() {
media.getActivePeers().then((devicesInfo) => { media.getActivePeers().then((devicesInfo) => {
if (devicesInfo != undefined) { if (devicesInfo != undefined) {
for (let i = 0; i < devicesInfo.length; i++) { console.info('get distributed info ' + JSON.stringify(devicesInfo));
console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
}
} else { } else {
console.info('get distributed info is undefined!') console.info('get distributed info is undefined!');
} }
}).catch((err) => { }).catch((error) => {
console.error("get distributed info failed with error:" + err); 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 ...@@ -927,15 +959,13 @@ Obtains information about online peer devices. This API uses an asynchronous cal
```js ```js
async function example() { async function example() {
media.getActivePeers((err, devicesInfo) => { media.getActivePeers((error, devicesInfo) => {
if (devicesInfo != undefined) { if (devicesInfo != undefined) {
for (let i = 0; i < devicesInfo.length; i++) { console.info('get distributed info ' + JSON.stringify(devicesInfo));
console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
}
} else { } 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 ...@@ -964,14 +994,12 @@ Obtains information about all peer devices. This API uses a promise to return th
async function example() { async function example() {
media.getAllPeers().then((devicesInfo) => { media.getAllPeers().then((devicesInfo) => {
if (devicesInfo != undefined) { if (devicesInfo != undefined) {
for (let i = 0; i < devicesInfo.length; i++) { console.info('get distributed info ' + JSON.stringify(devicesInfo));
console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
}
} else { } else {
console.info('get distributed info is undefined!') console.info('get distributed info is undefined!');
} }
}).catch((err) => { }).catch((error) => {
console.error("get distributed info failed with error: " + err); 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 ...@@ -998,15 +1026,13 @@ Obtains information about online peer devices. This API uses an asynchronous cal
```js ```js
async function example() { async function example() {
media.getAllPeers((err, devicesInfo) => { media.getAllPeers((error, devicesInfo) => {
if (devicesInfo != undefined) { if (devicesInfo != undefined) {
for (let i = 0; i < devicesInfo.length; i++) { console.info('get distributed info ' + JSON.stringify(devicesInfo));
console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
}
} else { } 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 ...@@ -1068,19 +1094,23 @@ Checks whether this file asset is a directory. This API uses an asynchronous cal
```js ```js
async function example() { async function example() {
let fileKeyObj = mediaLibrary.FileKey let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.isDirectory((err, isDirectory) => { asset.isDirectory((error, isDirectory) => {
// do something 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 ...@@ -1104,21 +1134,21 @@ Checks whether this file asset is a directory. This API uses a promise to return
```js ```js
async function example() { async function example() {
let fileKeyObj = mediaLibrary.FileKey let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.isDirectory().then(function(isDirectory){ asset.isDirectory().then((isDirectory) => {
console.info("isDirectory result:"+ isDirectory); console.info('isDirectory result:' + isDirectory);
}).catch(function(err){ }).catch((error) => {
console.error("isDirectory failed with error: " + err); 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 ...@@ -1142,20 +1172,20 @@ Commits the modification in this file asset to the database. This API uses an as
```js ```js
async function example() { async function example() {
let fileKeyObj = mediaLibrary.FileKey let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.title = 'newtitle'; asset.title = 'newtitle';
asset.commitModify(() => { 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 ...@@ -1179,18 +1209,18 @@ Commits the modification in this file asset to the database. This API uses a pro
```js ```js
async function example() { async function example() {
let fileKeyObj = mediaLibrary.FileKey let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.title = 'newtitle'; asset.title = 'newtitle';
asset.commitModify(); await asset.commitModify();
fetchFileResult.close();
} }
``` ```
...@@ -1200,9 +1230,7 @@ open(mode: string, callback: AsyncCallback&lt;number&gt;): void ...@@ -1200,9 +1230,7 @@ open(mode: string, callback: AsyncCallback&lt;number&gt;): void
Opens this file asset. This API uses an asynchronous callback to return the result. Opens this file asset. This API uses an asynchronous callback to return the result.
> **NOTE** **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.
>
> Currently, the write operations are mutually exclusive. After the write operation is complete, you must call **close** to release the resource.
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA **Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
...@@ -1222,13 +1250,13 @@ async function example() { ...@@ -1222,13 +1250,13 @@ async function example() {
let mediaType = mediaLibrary.MediaType.IMAGE; let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE); const path = await media.getPublicDirectory(DIR_IMAGE);
const asset = await media.createAsset(mediaType, "image00003.jpg", path); const asset = await media.createAsset(mediaType, 'image00003.jpg', path);
asset.open('rw', (openError, fd) => { asset.open('rw', (error, fd) => {
if(fd > 0){ if (fd > 0) {
asset.close(fd); asset.close(fd);
}else{ } else {
console.error('File Open Failed!' + openError); console.error('File Open failed with error: ' + error);
} }
}); });
} }
``` ```
...@@ -1239,9 +1267,7 @@ open(mode: string): Promise&lt;number&gt; ...@@ -1239,9 +1267,7 @@ open(mode: string): Promise&lt;number&gt;
Opens this file asset. This API uses a promise to return the result. Opens this file asset. This API uses a promise to return the result.
> **NOTE** **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.
>
> Currently, the write operations are mutually exclusive. After the write operation is complete, you must call **close** to release the resource.
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA **Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
...@@ -1266,14 +1292,12 @@ async function example() { ...@@ -1266,14 +1292,12 @@ async function example() {
let mediaType = mediaLibrary.MediaType.IMAGE; let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE); const path = await media.getPublicDirectory(DIR_IMAGE);
const asset = await media.createAsset(mediaType, "image00003.jpg", path); const asset = await media.createAsset(mediaType, 'image00003.jpg', path);
asset.open('rw') asset.open('rw').then((fd) => {
.then((fd) => { console.info('File open fd: ' + fd);
console.info('File fd!' + fd); }).catch((error) => {
}) console.error('File open failed with error: ' + error);
.catch((err) => { });
console.error('File err!' + err);
});
} }
``` ```
...@@ -1298,30 +1322,28 @@ Closes this file asset. This API uses an asynchronous callback to return the res ...@@ -1298,30 +1322,28 @@ Closes this file asset. This API uses an asynchronous callback to return the res
```js ```js
async function example() { async function example() {
let fileKeyObj = mediaLibrary.FileKey let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.open('rw').then((fd) => { asset.open('rw').then((fd) => {
console.info('File fd!' + fd); console.info('File open fd: ' + fd);
asset.close(fd, (closeErr) => { asset.close(fd, (error) => {
if (closeErr != undefined) { if (error) {
console.error('mediaLibraryTest : close : FAIL ' + closeErr); console.error('asset.close failed with error: ' + error);
console.error('mediaLibraryTest : ASSET_CALLBACK : FAIL');
} else { } else {
console.info("=======asset.close success====>"); console.info('asset.close successfully');
} }
}); });
}) }).catch((error) => {
.catch((err) => { console.error('File open failed with error: ' + error);
console.error('File err!' + err);
}); });
fetchFileResult.close();
} }
``` ```
...@@ -1351,31 +1373,26 @@ Closes this file asset. This API uses a promise to return the result. ...@@ -1351,31 +1373,26 @@ Closes this file asset. This API uses a promise to return the result.
```js ```js
async function example() { async function example() {
let fileKeyObj = mediaLibrary.FileKey let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.open('rw').then((fd) => { asset.open('rw').then((fd) => {
console.info('File fd!' + fd); console.info('File fd!' + fd);
asset.close(fd).then((closeErr) => { asset.close(fd).then(() => {
if (closeErr != undefined) { console.info('asset.close successfully');
console.error('mediaLibraryTest : close : FAIL ' + closeErr); }).catch((closeErr) => {
console.error('mediaLibraryTest : ASSET_CALLBACK : FAIL'); console.error('asset.close fail, closeErr: ' + closeErr);
} else {
console.info("=======asset.close success====>");
}
}); });
}) }).catch((error) => {
.catch((err) => { console.error('open File failed with error: ' + error);
console.error('File err!' + err);
}); });
fetchFileResult.close();
} }
``` ```
...@@ -1399,19 +1416,23 @@ Obtains the thumbnail of this file asset. This API uses an asynchronous callback ...@@ -1399,19 +1416,23 @@ Obtains the thumbnail of this file asset. This API uses an asynchronous callback
```js ```js
async function example() { async function example() {
let fileKeyObj = mediaLibrary.FileKey let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.getThumbnail((err, pixelmap) => { asset.getThumbnail((error, pixelmap) => {
console.info('mediaLibraryTest : getThumbnail Successful '+ 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() { ...@@ -1439,17 +1460,21 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let size = { width: 720, height: 720 }; let size = { width: 720, height: 720 };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.getThumbnail(size, (err, pixelmap) => { asset.getThumbnail(size, (error, pixelmap) => {
console.info('mediaLibraryTest : getThumbnail Successful '+ 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() { ...@@ -1484,19 +1509,17 @@ async function example() {
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let size = { width: 720, height: 720 }; let size = { width: 720, height: 720 };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.getThumbnail(size) asset.getThumbnail(size).then((pixelmap) => {
.then((pixelmap) => { console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
console.info('mediaLibraryTest : getThumbnail Successful '+ pixelmap); }).catch((error) => {
}) console.error('mediaLibrary getThumbnail failed with error: ' + error);
.catch((err) => {
console.error('mediaLibraryTest : getThumbnail fail, err: ' + err);
}); });
fetchFileResult.close();
} }
``` ```
...@@ -1524,16 +1547,20 @@ async function example() { ...@@ -1524,16 +1547,20 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.favorite(true,function(err){ asset.favorite(true,(error) => {
// do something 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() { ...@@ -1566,18 +1593,18 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.favorite(true).then(function() { asset.favorite(true).then(() => {
console.info("favorite successfully"); console.info('mediaLibrary favorite Successful');
}).catch(function(err){ }).catch((error) => {
console.error("favorite failed with error: " + err); console.error('mediaLibrary favorite failed with error: ' + error);
}); });
fetchFileResult.close();
} }
``` ```
...@@ -1604,20 +1631,20 @@ async function example() { ...@@ -1604,20 +1631,20 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.isFavorite((err, isFavorite) => { asset.isFavorite((error, isFavorite) => {
if (isFavorite) { if (error) {
console.info('FileAsset is favorite'); console.error('mediaLibrary favoriisFavoritete failed with error: ' + error);
}else{ } else {
console.info('FileAsset is not favorite'); console.info('mediaLibrary isFavorite Successful, isFavorite result: ' + isFavorite);
} }
}); });
fetchFileResult.close();
} }
``` ```
...@@ -1644,18 +1671,18 @@ async function example() { ...@@ -1644,18 +1671,18 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.isFavorite().then(function(isFavorite){ asset.isFavorite().then((isFavorite) => {
console.info("isFavorite result:"+ isFavorite); console.info('mediaLibrary isFavorite Successful, isFavorite result: ' + isFavorite);
}).catch(function(err){ }).catch((error) => {
console.error("isFavorite failed with error: " + err); console.error('mediaLibrary favoriisFavoritete failed with error: ' + error);
}); });
fetchFileResult.close();
} }
``` ```
...@@ -1685,17 +1712,20 @@ async function example() { ...@@ -1685,17 +1712,20 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.trash(true, trashCallBack); asset.trash(true, (error) => {
function trashCallBack(err, trash) { if (error) {
console.info('mediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK trash'); console.error('mediaLibrary trash failed with error: ' + error);
} } else {
console.info('mediaLibrary trash Successful');
}
});
fetchFileResult.close();
} }
``` ```
...@@ -1730,18 +1760,18 @@ async function example() { ...@@ -1730,18 +1760,18 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.trash(true).then(function() { asset.trash(true).then(() => {
console.info("trash successfully"); console.info('trash successfully');
}).catch(function(err){ }).catch((error) => {
console.error("trash failed with error: " + err); console.error('trash failed with error: ' + error);
}); });
fetchFileResult.close();
} }
``` ```
...@@ -1768,20 +1798,20 @@ async function example() { ...@@ -1768,20 +1798,20 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.isTrash((err, isTrash) => { asset.isTrash((error, isTrash) => {
if (isTrash == undefined) { if (error) {
console.error('Failed to get trash state: ' + err); console.error('Failed to get trash state failed with error: ' + error);
return; return;
} }
console.info('Get trash state success: ' + isTrash); console.info('Get trash state successfully, isTrash result: ' + isTrash);
}); });
fetchFileResult.close();
} }
``` ```
...@@ -1808,17 +1838,18 @@ async function example() { ...@@ -1808,17 +1838,18 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
}; };
const fetchFileResult = await media.getFileAssets(getImageOp); const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.isTrash().then(function(isTrash){ asset.isTrash().then((isTrash) => {
console.info("isTrash result: " + isTrash); console.info('isTrash result: ' + isTrash);
}).catch(function(err){ }).catch((error) => {
console.error("isTrash failed with error: " + err); console.error('isTrash failed with error: ' + error);
}); });
fetchFileResult.close();
} }
``` ```
...@@ -1849,11 +1880,12 @@ async function example() { ...@@ -1849,11 +1880,12 @@ async function example() {
let getFileCountOneOp = { let getFileCountOneOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [fileType.toString()], selectionArgs: [fileType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let fetchFileResult = await media.getFileAssets(getFileCountOneOp); let fetchFileResult = await media.getFileAssets(getFileCountOneOp);
const fetchCount = fetchFileResult.getCount(); const fetchCount = fetchFileResult.getCount();
console.info('fetchCount result: ' + fetchCount);
fetchFileResult.close();
} }
``` ```
...@@ -1878,25 +1910,22 @@ async function example() { ...@@ -1878,25 +1910,22 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let fetchFileResult = await media.getFileAssets(getImageOp); let fetchFileResult = await media.getFileAssets(getImageOp);
const fetchCount = fetchFileResult.getCount(); const fetchCount = fetchFileResult.getCount();
console.info('mediaLibraryTest : count:' + fetchCount); console.info('mediaLibrary fetchFileResult.getCount, count:' + fetchCount);
let fileAsset = await fetchFileResult.getFirstObject(); let fileAsset = await fetchFileResult.getFirstObject();
for (var i = 1; i < fetchCount; i++) { for (var i = 1; i < fetchCount; i++) {
fileAsset = await fetchFileResult.getNextObject(); fileAsset = await fetchFileResult.getNextObject();
if(i == fetchCount - 1) { if(i == fetchCount - 1) {
console.info('mediaLibraryTest : isLast'); var result = fetchFileResult.isAfterLast();
var result = fetchFileResult.isAfterLast(); console.info('mediaLibrary fileAsset isAfterLast result: ' + result);
console.info('mediaLibraryTest : isAfterLast:' + result); }
console.info('mediaLibraryTest : isAfterLast end');
fetchFileResult.close();
}
} }
fetchFileResult.close();
} }
``` ```
...@@ -1915,10 +1944,9 @@ async function example() { ...@@ -1915,10 +1944,9 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let fetchFileResult = await media.getFileAssets(getImageOp); let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.close(); fetchFileResult.close();
...@@ -1946,19 +1974,19 @@ async function example() { ...@@ -1946,19 +1974,19 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let fetchFileResult = await media.getFileAssets(getImageOp); let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getFirstObject((err, fileAsset) => { fetchFileResult.getFirstObject((error, fileAsset) => {
if (err) { if (error) {
console.error('Failed '); console.error('fetchFileResult getFirstObject failed with error: ' + error);
return; return;
} }
console.info('fileAsset.displayName : ' + fileAsset.displayName); console.info('getFirstObject successfully, displayName : ' + fileAsset.displayName);
}) })
fetchFileResult.close();
} }
``` ```
...@@ -1983,17 +2011,17 @@ async function example() { ...@@ -1983,17 +2011,17 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let fetchFileResult = await media.getFileAssets(getImageOp); let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getFirstObject().then(function(fileAsset){ fetchFileResult.getFirstObject().then((fileAsset) => {
console.info("getFirstObject successfully:"+ JSON.stringify(fileAsset)); console.info('getFirstObject successfully, displayName: ' + fileAsset.displayName);
}).catch(function(err){ }).catch((error) => {
console.error("getFirstObject failed with error: " + err); console.error('getFirstObject failed with error: ' + error);
}); });
fetchFileResult.close();
} }
``` ```
...@@ -2002,6 +2030,9 @@ async function example() { ...@@ -2002,6 +2030,9 @@ async function example() {
getNextObject(callback: AsyncCallback&lt;FileAsset&gt;): void getNextObject(callback: AsyncCallback&lt;FileAsset&gt;): void
Obtains the next file asset in the result set. This API uses an asynchronous callback to return the result. 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 **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -2018,20 +2049,24 @@ async function example() { ...@@ -2018,20 +2049,24 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let fetchFileResult = await media.getFileAssets(getImageOp); let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getNextObject((err, fileAsset) => { let fileAsset = await fetchFileResult.getFirstObject();
if (err) { if (! fetchFileResult.isAfterLast) {
console.error('Failed '); fetchFileResult.getNextObject((error, fileAsset) => {
return; if (error) {
} console.error('fetchFileResult getNextObject failed with error: ' + error);
console.log('fileAsset.displayName : ' + fileAsset.displayName); return;
}) }
console.log('fetchFileResult getNextObject successfully, displayName: ' + fileAsset.displayName);
})
}
fetchFileResult.close();
} }
``` ```
### getNextObject<sup>7+</sup> ### getNextObject<sup>7+</sup>
...@@ -2039,6 +2074,9 @@ async function example() { ...@@ -2039,6 +2074,9 @@ async function example() {
getNextObject(): Promise&lt;FileAsset&gt; getNextObject(): Promise&lt;FileAsset&gt;
Obtains the next file asset in the result set. This API uses a promise to return the result. 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 **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -2055,15 +2093,20 @@ async function example() { ...@@ -2055,15 +2093,20 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let fetchFileResult = await media.getFileAssets(getImageOp); let fetchFileResult = await media.getFileAssets(getImageOp);
const fetchCount = fetchFileResult.getCount(); let fileAsset = await fetchFileResult.getFirstObject();
console.info('mediaLibraryTest : count:' + fetchCount); if (! fetchFileResult.isAfterLast) {
let fileAsset = await fetchFileResult.getNextObject(); 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() { ...@@ -2088,19 +2131,19 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let fetchFileResult = await media.getFileAssets(getImageOp); let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getLastObject((err, fileAsset) => { fetchFileResult.getLastObject((error, fileAsset) => {
if (err) { if (error) {
console.error('Failed '); console.error('getLastObject failed with error: ' + error);
return; return;
} }
console.info('fileAsset.displayName : ' + fileAsset.displayName); console.info('getLastObject successfully, displayName: ' + fileAsset.displayName);
}) })
fetchFileResult.close();
} }
``` ```
...@@ -2125,13 +2168,17 @@ async function example() { ...@@ -2125,13 +2168,17 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let fetchFileResult = await media.getFileAssets(getImageOp); 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 ...@@ -2147,7 +2194,7 @@ Obtains a file asset with the specified index in the result set. This API uses a
| Name | Type | Mandatory | Description | | 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&lt;[FileAsset](#fileasset7)&gt; | Yes | Callback used to return the last file asset.| | callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes | Callback used to return the last file asset.|
**Example** **Example**
...@@ -2157,19 +2204,19 @@ async function example() { ...@@ -2157,19 +2204,19 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let fetchFileResult = await media.getFileAssets(getImageOp); let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getPositionObject(0, (err, fileAsset) => { fetchFileResult.getPositionObject(0, (error, fileAsset) => {
if (err) { if (error) {
console.error('Failed '); console.error('getPositionObject failed with error: ' + error);
return; return;
} }
console.info('fileAsset.displayName : ' + fileAsset.displayName); 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 ...@@ -2185,7 +2232,7 @@ Obtains a file asset with the specified index in the result set. This API uses a
| Name | Type | Mandatory | Description | | 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** **Return value**
...@@ -2200,17 +2247,17 @@ async function example() { ...@@ -2200,17 +2247,17 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let fetchFileResult = await media.getFileAssets(getImageOp); let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getPositionObject(1) .then(function (fileAsset){ fetchFileResult.getPositionObject(0).then((fileAsset) => {
console.info('fileAsset.displayName : ' + fileAsset.displayName); console.info('getPositionObject successfully, displayName: ' + fileAsset.displayName);
}).catch(function (err) { }).catch((error) => {
console.error("getFileAssets failed with error: " + err); 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 ...@@ -2226,7 +2273,7 @@ Obtains all the file assets in the result set. This API uses an asynchronous cal
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | -------------------- | | -------- | ---------------------------------------- | ---- | -------------------- |
| callback | AsyncCallback<Array<[FileAsset](#fileasset7)>> | Yes | Callback used to return the file assets.| | callback | AsyncCallback&lt;Array&lt;[FileAsset](#fileasset7)&gt;&gt; | Yes | Callback used to return the file assets.|
**Example** **Example**
...@@ -2235,21 +2282,21 @@ async function example() { ...@@ -2235,21 +2282,21 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let fetchFileResult = await media.getFileAssets(getImageOp); let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getAllObject((err, fileAsset) => { fetchFileResult.getAllObject((error, fileAssetList) => {
if (err) { if (error) {
console.error('Failed '); console.error('getAllObject failed with error: ' + error);
return; return;
} }
for (let i = 0; i < fetchFileResult.getCount(); i++) { 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 ...@@ -2265,7 +2312,7 @@ Obtains all the file assets in the result set. This API uses a promise to return
| Type | Description | | Type | Description |
| ---------------------------------------- | --------------------- | | ---------------------------------------- | --------------------- |
| Promise<Array<[FileAsset](#fileasset7)>> | Promise used to return the file assets.| | Promise&lt;Array&lt;[FileAsset](#fileasset7)&gt;&gt; | Promise used to return the file assets.|
**Example** **Example**
...@@ -2274,13 +2321,19 @@ async function example() { ...@@ -2274,13 +2321,19 @@ async function example() {
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = { let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC", order: fileKeyObj.DATE_ADDED + ' DESC',
extendArgs: "",
}; };
let fetchFileResult = await media.getFileAssets(getImageOp); 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() { ...@@ -2329,12 +2382,12 @@ async function example() {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp); const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0]; const album = albumList[0];
album.albumName = 'hello'; album.albumName = 'hello';
album.commitModify((err) => { album.commitModify((error) => {
if (err) { if (error) {
console.error('Failed '); console.error('commitModify failed with error: ' + error);
return; return;
} }
console.info('Modify successful.'); console.info('commitModify successful.');
}) })
} }
``` ```
...@@ -2366,10 +2419,10 @@ async function example() { ...@@ -2366,10 +2419,10 @@ async function example() {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp); const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0]; const album = albumList[0];
album.albumName = 'hello'; album.albumName = 'hello';
album.commitModify().then(function() { album.commitModify().then(() => {
console.info("commitModify successfully"); console.info('commitModify successfully');
}).catch(function(err){ }).catch((error) => {
console.error("commitModify failed with error: " + err); console.error('commitModify failed with error: ' + error);
}); });
} }
``` ```
...@@ -2400,15 +2453,22 @@ async function example() { ...@@ -2400,15 +2453,22 @@ async function example() {
selectionArgs: [], selectionArgs: [],
}; };
let fileNoArgsfetchOp = { let fileNoArgsfetchOp = {
selections: '', selections: '',
selectionArgs: [], selectionArgs: [],
} }
// Obtain the albums that meet the retrieval options and return the album list.
const albumList = await media.getAlbums(AlbumNoArgsfetchOp); const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0]; const album = albumList[0];
album.getFileAssets(fileNoArgsfetchOp, getFileAssetsCallBack); // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album.
function getFileAssetsCallBack(err, fetchFileResult) { album.getFileAssets(fileNoArgsfetchOp, (error, fetchFileResult) => {
// do something 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() { ...@@ -2442,17 +2502,21 @@ async function example() {
selections: '', selections: '',
selectionArgs: [], selectionArgs: [],
}; };
let fileNoArgsfetchOp = { let fileNoArgsfetchOp = {
selections: '', selections: '',
selectionArgs: [], selectionArgs: [],
}; };
// Obtain the albums that meet the retrieval options and return the album list.
const albumList = await media.getAlbums(AlbumNoArgsfetchOp); const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0]; const album = albumList[0];
album.getFileAssets(fileNoArgsfetchOp).then(function(albumFetchFileResult){ // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album.
console.info("getFileAssets successfully: " + JSON.stringify(albumFetchFileResult)); album.getFileAssets(fileNoArgsfetchOp).then((albumFetchFileResult) => {
}).catch(function(err){ let count = fetchFileResult.getcount();
console.error("getFileAssets failed with error: " + err); 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. ...@@ -2491,32 +2555,32 @@ Enumerates media types.
Enumerates key file information. Enumerates key file information.
> **NOTE** > **NOTE**
> >
> The **bucket_id** field may change after file rename or movement. Therefore, you must obtain the field again before using it. > 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 **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
| Name | Value | Description | | Name | Value | Description |
| ------------- | ------------------- | ---------------------------------------------------------- | | ------------- | ------------------- | ---------------------------------------------------------- |
| ID | "file_id" | File ID. | | ID | 'file_id' | File ID. |
| RELATIVE_PATH | "relative_path" | Relative public directory of the file. | | RELATIVE_PATH | 'relative_path' | Relative public directory of the file. |
| DISPLAY_NAME | "display_name" | Display file name. | | DISPLAY_NAME | 'display_name' | Display file name. |
| PARENT | "parent" | Parent directory ID. | | PARENT | 'parent' | Parent directory ID. |
| MIME_TYPE | "mime_type" | Extended file attributes. | | MIME_TYPE | 'mime_type' | Extended file attributes, such as image/, video/, and file/*. |
| MEDIA_TYPE | "media_type" | Media type. | | MEDIA_TYPE | 'media_type' | Media type. |
| SIZE | "size" | File size, in bytes. | | 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_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_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. | | 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. | | TITLE | 'title' | Title in the file. |
| ARTIST | "artist" | Artist of the file. | | ARTIST | 'artist' | Artist of the file. |
| AUDIOALBUM | "audio_album" | Audio album. | | AUDIOALBUM | 'audio_album' | Audio album. |
| DURATION | "duration" | Duration, in ms. | | DURATION | 'duration' | Duration, in ms. |
| WIDTH | "width" | Image width, in pixels. | | WIDTH | 'width' | Image width, in pixels. |
| HEIGHT | "height" | Image height, in pixels. | | HEIGHT | 'height' | Image height, in pixels. |
| ORIENTATION | "orientation" | Image display direction (clockwise rotation angle, for example, 0, 90, and 180, in degrees).| | 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_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. | | ALBUM_NAME | 'bucket_display_name' | Name of the album to which the file belongs. |
## DirectoryType<sup>8+</sup> ## DirectoryType<sup>8+</sup>
...@@ -2559,9 +2623,9 @@ Describes options for fetching media files. ...@@ -2559,9 +2623,9 @@ Describes options for fetching media files.
| Name | Type | Readable| Writable| Description | | 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:<br>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:<br>selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ? OR ' + mediaLibrary.FileKey.MEDIA_TYPE + '= ?', |
| selectionArgs | Array&lt;string&gt; | Yes | Yes | Value of the condition, which corresponds to the value of the condition column in **selections**.<br>Example:<br>selectionArgs: [mediaLibrary.MediaType.IMAGE.toString(), mediaLibrary.MediaType.VIDEO.toString()], | | selectionArgs | Array&lt;string&gt; | Yes | Yes | Value of the condition, which corresponds to the value of the condition column in **selections**.<br>Example:<br>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:<br>Ascending: order: mediaLibrary.FileKey.DATE_ADDED + " ASC"<br>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:<br>Ascending: order: mediaLibrary.FileKey.DATE_ADDED + ' ASC'<br>Descending: order: mediaLibrary.FileKey.DATE_ADDED + ' DESC'|
| uri<sup>8+</sup> | string | Yes | Yes | File URI. | | uri<sup>8+</sup> | string | Yes | Yes | File URI. |
| networkId<sup>8+</sup> | string | Yes | Yes | Network ID of the registered device. | | networkId<sup>8+</sup> | string | Yes | Yes | Network ID of the registered device. |
| extendArgs<sup>8+</sup> | string | Yes | Yes | Extended parameters for fetching the files. Currently, no extended parameters are available. | | extendArgs<sup>8+</sup> | string | Yes | Yes | Extended parameters for fetching the files. Currently, no extended parameters are available. |
......
# @ohos.reminderAgentManager (Reminder Agent Management) # @ohos.reminderAgentManager (reminderAgentManager)
The **reminderAgentManager** module provides APIs for publishing scheduled reminders through the reminder agent. The **reminderAgentManager** module provides APIs for publishing scheduled reminders through the reminder agent.
...@@ -11,16 +11,14 @@ You can use the APIs to create scheduled reminders for countdown timers, calenda ...@@ -11,16 +11,14 @@ You can use the APIs to create scheduled reminders for countdown timers, calenda
## Modules to Import ## Modules to Import
```ts ```
import reminderAgentManager from'@ohos.reminderAgentManager'; import reminderAgentManager from'@ohos.reminderAgentManager';
``` ```
## reminderAgentManager.publishReminder ## reminderAgentManager.publishReminder
```ts publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback&lt;number&gt;): void
publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback<number>): void
```
Publishes a reminder through the reminder agent. This API uses an asynchronous callback to return the result. It can be called only when notification is enabled for the application through [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8). Publishes a reminder through the reminder agent. This API uses an asynchronous callback to return the result. It can be called only when notification is enabled for the application through [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8).
...@@ -33,7 +31,7 @@ Publishes a reminder through the reminder agent. This API uses an asynchronous c ...@@ -33,7 +31,7 @@ Publishes a reminder through the reminder agent. This API uses an asynchronous c
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| reminderReq | [ReminderRequest](#reminderrequest) | Yes| Reminder to be published.| | reminderReq | [ReminderRequest](#reminderrequest) | Yes| Reminder to be published.|
| callback | AsyncCallback\<number\> | Yes| Callback used to return the published reminder's ID.| | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the published reminder's ID.|
**Error codes** **Error codes**
...@@ -45,12 +43,11 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err ...@@ -45,12 +43,11 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err
| 1700002 | The number of reminders exceeds the limit. | | 1700002 | The number of reminders exceeds the limit. |
**Example** **Example**
```ts ```js
let timer = { let timer = {
reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_TIMER, reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 10 triggerTimeInSeconds: 10
} }
try { try {
reminderAgentManager.publishReminder(timer, (err, reminderId) => { reminderAgentManager.publishReminder(timer, (err, reminderId) => {
if (err) { if (err) {
...@@ -67,9 +64,7 @@ try { ...@@ -67,9 +64,7 @@ try {
## reminderAgentManager.publishReminder ## reminderAgentManager.publishReminder
```ts publishReminder(reminderReq: ReminderRequest): Promise&lt;number&gt;
publishReminder(reminderReq: ReminderRequest): Promise<number>
```
Publishes a reminder through the reminder agent. This API uses a promise to return the result. It can be called only when notification is enabled for the application through [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8). Publishes a reminder through the reminder agent. This API uses a promise to return the result. It can be called only when notification is enabled for the application through [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8).
...@@ -85,7 +80,7 @@ Publishes a reminder through the reminder agent. This API uses a promise to retu ...@@ -85,7 +80,7 @@ Publishes a reminder through the reminder agent. This API uses a promise to retu
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<number\> | Promise used to return the published reminder's ID.| | Promise&lt;number&gt; | Promise used to return the published reminder's ID.|
**Error codes** **Error codes**
...@@ -97,12 +92,11 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err ...@@ -97,12 +92,11 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err
| 1700002 | The number of reminders exceeds the limit. | | 1700002 | The number of reminders exceeds the limit. |
**Example** **Example**
```ts ```js
let timer = { let timer = {
reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_TIMER, reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 10 triggerTimeInSeconds: 10
} }
try { try {
reminderAgentManager.publishReminder(timer).then((reminderId) => { reminderAgentManager.publishReminder(timer).then((reminderId) => {
console.log("promise, reminderId = " + reminderId); console.log("promise, reminderId = " + reminderId);
...@@ -117,9 +111,7 @@ try { ...@@ -117,9 +111,7 @@ try {
## reminderAgentManager.cancelReminder ## reminderAgentManager.cancelReminder
```ts cancelReminder(reminderId: number, callback: AsyncCallback&lt;void&gt;): void
cancelReminder(reminderId: number, callback: AsyncCallback<void>): void
```
Cancels the reminder with the specified ID. This API uses an asynchronous callback to return the cancellation result. Cancels the reminder with the specified ID. This API uses an asynchronous callback to return the cancellation result.
...@@ -130,7 +122,7 @@ Cancels the reminder with the specified ID. This API uses an asynchronous callba ...@@ -130,7 +122,7 @@ Cancels the reminder with the specified ID. This API uses an asynchronous callba
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| reminderId | number | Yes| ID of the reminder to cancel.| | reminderId | number | Yes| ID of the reminder to cancel.|
| callback | AsyncCallback\<void\> | Yes| Asynchronous callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Asynchronous callback used to return the result.|
**Error codes** **Error codes**
...@@ -143,7 +135,7 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err ...@@ -143,7 +135,7 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err
**Example** **Example**
```ts ```js
try { try {
reminderAgentManager.cancelReminder(1, (err, data) => { reminderAgentManager.cancelReminder(1, (err, data) => {
if (err) { if (err) {
...@@ -160,9 +152,7 @@ try { ...@@ -160,9 +152,7 @@ try {
## reminderAgentManager.cancelReminder ## reminderAgentManager.cancelReminder
```ts cancelReminder(reminderId: number): Promise&lt;void&gt;
cancelReminder(reminderId: number): Promise<void>
```
Cancels the reminder with the specified ID. This API uses a promise to return the cancellation result. Cancels the reminder with the specified ID. This API uses a promise to return the cancellation result.
...@@ -178,7 +168,7 @@ Cancels the reminder with the specified ID. This API uses a promise to return th ...@@ -178,7 +168,7 @@ Cancels the reminder with the specified ID. This API uses a promise to return th
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<void\> | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Error codes** **Error codes**
...@@ -191,7 +181,7 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err ...@@ -191,7 +181,7 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err
**Example** **Example**
```ts ```js
try { try {
reminderAgentManager.cancelReminder(1).then(() => { reminderAgentManager.cancelReminder(1).then(() => {
console.log("cancelReminder promise"); console.log("cancelReminder promise");
...@@ -203,12 +193,10 @@ try { ...@@ -203,12 +193,10 @@ try {
}; };
``` ```
## reminderAgentManager.getValidReminders
```ts ## reminderAgentManager.getValidReminders
getValidReminders(callback: AsyncCallback<Array<ReminderRequest>>): void
``` getValidReminders(callback: AsyncCallback&lt;Array&lt;ReminderRequest&gt;&gt;): void
Obtains all valid (not yet expired) reminders set by the current application. This API uses an asynchronous callback to return the reminders. Obtains all valid (not yet expired) reminders set by the current application. This API uses an asynchronous callback to return the reminders.
...@@ -218,7 +206,7 @@ Obtains all valid (not yet expired) reminders set by the current application. Th ...@@ -218,7 +206,7 @@ Obtains all valid (not yet expired) reminders set by the current application. Th
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<Array\<[ReminderRequest](#reminderrequest)\>\> | Yes| Asynchronous callback used to return an array of all valid reminders set by the current application.| | callback | AsyncCallback&lt;Array&lt;[ReminderRequest](#reminderrequest)&gt;&gt; | Yes| Asynchronous callback used to return an array of all valid reminders set by the current application.|
**Error codes** **Error codes**
...@@ -230,7 +218,7 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err ...@@ -230,7 +218,7 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err
**Example** **Example**
```ts ```js
try { try {
reminderAgentManager.getValidReminders((err, reminders) => { reminderAgentManager.getValidReminders((err, reminders) => {
if (err) { if (err) {
...@@ -265,11 +253,10 @@ try { ...@@ -265,11 +253,10 @@ try {
}; };
``` ```
## reminderAgentManager.getValidReminders ## reminderAgentManager.getValidReminders
```ts getValidReminders(): Promise&lt;Array&lt;ReminderRequest&gt;&gt;
getValidReminders(): Promise<Array<ReminderRequest>>
```
Obtains all valid (not yet expired) reminders set by the current application. This API uses a promise to return the reminders. Obtains all valid (not yet expired) reminders set by the current application. This API uses a promise to return the reminders.
...@@ -279,7 +266,7 @@ Obtains all valid (not yet expired) reminders set by the current application. Th ...@@ -279,7 +266,7 @@ Obtains all valid (not yet expired) reminders set by the current application. Th
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<Array\<[ReminderRequest](#reminderrequest)\>\> | Promise used to return an array of all valid reminders set by the current application.| | Promise&lt;Array&lt;[ReminderRequest](#reminderrequest)&gt;&gt; | Promise used to return an array of all valid reminders set by the current application.|
**Error codes** **Error codes**
...@@ -291,7 +278,7 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err ...@@ -291,7 +278,7 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err
**Example** **Example**
```ts ```js
try { try {
reminderAgentManager.getValidReminders().then((reminders) => { reminderAgentManager.getValidReminders().then((reminders) => {
console.log("promise, getValidReminders length = " + reminders.length); console.log("promise, getValidReminders length = " + reminders.length);
...@@ -327,9 +314,7 @@ try { ...@@ -327,9 +314,7 @@ try {
## reminderAgentManager.cancelAllReminders ## reminderAgentManager.cancelAllReminders
```ts cancelAllReminders(callback: AsyncCallback&lt;void&gt;): void
cancelAllReminders(callback: AsyncCallback<void>): void
```
Cancels all reminders set by the current application. This API uses an asynchronous callback to return the cancellation result. Cancels all reminders set by the current application. This API uses an asynchronous callback to return the cancellation result.
...@@ -339,7 +324,7 @@ Cancels all reminders set by the current application. This API uses an asynchron ...@@ -339,7 +324,7 @@ Cancels all reminders set by the current application. This API uses an asynchron
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<void\> | Yes| Asynchronous callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Asynchronous callback used to return the result.|
**Error codes** **Error codes**
...@@ -351,7 +336,7 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err ...@@ -351,7 +336,7 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err
**Example** **Example**
```ts ```js
try { try {
reminderAgentManager.cancelAllReminders((err, data) =>{ reminderAgentManager.cancelAllReminders((err, data) =>{
if (err) { if (err) {
...@@ -368,9 +353,7 @@ try { ...@@ -368,9 +353,7 @@ try {
## reminderAgentManager.cancelAllReminders ## reminderAgentManager.cancelAllReminders
```ts cancelAllReminders(): Promise&lt;void&gt;
cancelAllReminders(): Promise<void>
```
Cancels all reminders set by the current application. This API uses a promise to return the cancellation result. Cancels all reminders set by the current application. This API uses a promise to return the cancellation result.
...@@ -380,7 +363,7 @@ Cancels all reminders set by the current application. This API uses a promise to ...@@ -380,7 +363,7 @@ Cancels all reminders set by the current application. This API uses a promise to
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<void\> | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Error codes** **Error codes**
...@@ -392,7 +375,7 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err ...@@ -392,7 +375,7 @@ For details about the error codes, see [reminderAgentManager Error Codes](../err
**Example** **Example**
```ts ```js
try { try {
reminderAgentManager.cancelAllReminders().then(() => { reminderAgentManager.cancelAllReminders().then(() => {
console.log("cancelAllReminders promise") console.log("cancelAllReminders promise")
...@@ -407,9 +390,7 @@ try { ...@@ -407,9 +390,7 @@ try {
## reminderAgentManager.addNotificationSlot ## reminderAgentManager.addNotificationSlot
```ts addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback&lt;void&gt;): void
addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback<void>): void
```
Adds a notification slot. This API uses an asynchronous callback to return the result. Adds a notification slot. This API uses an asynchronous callback to return the result.
...@@ -420,11 +401,11 @@ Adds a notification slot. This API uses an asynchronous callback to return the r ...@@ -420,11 +401,11 @@ Adds a notification slot. This API uses an asynchronous callback to return the r
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | Yes| Notification slot, whose type can be set.| | slot | [NotificationSlot](js-apis-notification.md#notificationslot) | Yes| Notification slot, whose type can be set.|
| callback | AsyncCallback\<void\> | Yes| Asynchronous callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Asynchronous callback used to return the result.|
**Example** **Example**
```ts ```js
import notification from '@ohos.notification' import notification from '@ohos.notification'
let mySlot = { let mySlot = {
...@@ -446,9 +427,7 @@ try { ...@@ -446,9 +427,7 @@ try {
## reminderAgentManager.addNotificationSlot ## reminderAgentManager.addNotificationSlot
```ts addNotificationSlot(slot: NotificationSlot): Promise&lt;void&gt;
addNotificationSlot(slot: NotificationSlot): Promise<void>
```
Adds a notification slot. This API uses a promise to return the result. Adds a notification slot. This API uses a promise to return the result.
...@@ -464,11 +443,11 @@ Adds a notification slot. This API uses a promise to return the result. ...@@ -464,11 +443,11 @@ Adds a notification slot. This API uses a promise to return the result.
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<void\> | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```ts ```js
import notification from '@ohos.notification' import notification from '@ohos.notification'
let mySlot = { let mySlot = {
...@@ -488,9 +467,7 @@ try { ...@@ -488,9 +467,7 @@ try {
## reminderAgentManager.removeNotificationSlot ## reminderAgentManager.removeNotificationSlot
```ts removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback&lt;void&gt;): void
removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback<void>): void
```
Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result. Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result.
...@@ -501,11 +478,11 @@ Removes a notification slot of a specified type. This API uses an asynchronous c ...@@ -501,11 +478,11 @@ Removes a notification slot of a specified type. This API uses an asynchronous c
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| slotType | [notification.SlotType](js-apis-notification.md#slottype) | Yes| Type of the notification slot to remove.| | slotType | [notification.SlotType](js-apis-notification.md#slottype) | Yes| Type of the notification slot to remove.|
| callback | AsyncCallback\<void\> | Yes| Asynchronous callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Asynchronous callback used to return the result.|
**Example** **Example**
```ts ```js
import notification from '@ohos.notification' import notification from '@ohos.notification'
try { try {
...@@ -524,9 +501,7 @@ try { ...@@ -524,9 +501,7 @@ try {
## reminderAgentManager.removeNotificationSlot ## reminderAgentManager.removeNotificationSlot
```ts removeNotificationSlot(slotType: notification.SlotType): Promise&lt;void&gt;
removeNotificationSlot(slotType: notification.SlotType): Promise<void>
```
Removes a notification slot of a specified type. This API uses a promise to return the result. Removes a notification slot of a specified type. This API uses a promise to return the result.
...@@ -542,11 +517,11 @@ Removes a notification slot of a specified type. This API uses a promise to retu ...@@ -542,11 +517,11 @@ Removes a notification slot of a specified type. This API uses a promise to retu
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<void\> | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```ts ```js
import notification from '@ohos.notification' import notification from '@ohos.notification'
try { try {
...@@ -655,8 +630,8 @@ Defines a reminder for a calendar event. ...@@ -655,8 +630,8 @@ Defines a reminder for a calendar event.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dateTime | [LocalDateTime](#localdatetime) | Yes| Reminder time.| | dateTime | [LocalDateTime](#localdatetime) | Yes| Reminder time.|
| repeatMonths | Array\<number\> | No| Month in which the reminder repeats.| | repeatMonths | Array&lt;number&gt; | No| Month in which the reminder repeats.|
| repeatDays | Array\<number\> | No| Date on which the reminder repeats.| | repeatDays | Array&lt;number&gt; | No| Date on which the reminder repeats.|
## ReminderRequestAlarm ## ReminderRequestAlarm
...@@ -671,7 +646,7 @@ Defines a reminder for an alarm. ...@@ -671,7 +646,7 @@ Defines a reminder for an alarm.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| hour | number | Yes| Hour portion of the reminder time.| | hour | number | Yes| Hour portion of the reminder time.|
| minute | number | Yes| Minute portion of the reminder time.| | minute | number | Yes| Minute portion of the reminder time.|
| daysOfWeek | Array\<number\> | No| Days of a week when the reminder repeats. The value ranges from 1 to 7, corresponding to the data from Monday to Sunday.| | daysOfWeek | Array&lt;number&gt; | No| Days of a week when the reminder repeats. The value ranges from 1 to 7, corresponding to the data from Monday to Sunday.|
## ReminderRequestTimer ## ReminderRequestTimer
...@@ -696,8 +671,8 @@ Sets the time information for a calendar reminder. ...@@ -696,8 +671,8 @@ Sets the time information for a calendar reminder.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| year | number | Yes| Year.| | year | number | Yes| Year.|
| month | number | Yes| Month.| | month | number | Yes| Month. The value ranges from 1 to 12.|
| day | number | Yes| Date.| | day | number | Yes| Day. The value ranges from 1 to 31.|
| hour | number | Yes| Hour.| | hour | number | Yes| Hour. The value ranges from 0 to 23.|
| minute | number | Yes| Minute.| | minute | number | Yes| Minute. The value ranges from 0 to 59.|
| second | number | No| Second.| | second | number | No| Second. The value ranges from 0 to 59.|
...@@ -26,7 +26,7 @@ Formats the specified values and inserts them into the string by replacing the w ...@@ -26,7 +26,7 @@ Formats the specified values and inserts them into the string by replacing the w
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | -------- | ---- | -------------- | | ------- | -------- | ---- | -------------- |
| format | string | Yes | String.| | 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** **Return value**
...@@ -69,6 +69,20 @@ let result = util.errnoToString(errnum); ...@@ -69,6 +69,20 @@ let result = util.errnoToString(errnum);
console.log("result = " + result); 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 ## util.callbackWrapper
callbackWrapper(original: Function): (err: Object, value: Object )=&gt;void callbackWrapper(original: Function): (err: Object, value: Object )=&gt;void
...@@ -92,15 +106,14 @@ Calls back an asynchronous function. In the callback, the first parameter indica ...@@ -92,15 +106,14 @@ Calls back an asynchronous function. In the callback, the first parameter indica
**Example** **Example**
```js ```js
async function promiseFn() { async function fn() {
return Promise.reject('value'); return 'hello world';
} }
let err = "type err"; let cb = util.callbackWrapper(fn);
let cb = util.callbackWrapper(promiseFn); cb((err, ret) => {
cb((err, ret) => { if (err) throw err;
console.log(err); console.log(ret);
console.log(ret); });
}, err)
``` ```
## util.promisify<sup>9+</sup> ## util.promisify<sup>9+</sup>
...@@ -126,24 +139,30 @@ Processes an asynchronous function and returns a promise. ...@@ -126,24 +139,30 @@ Processes an asynchronous function and returns a promise.
**Example** **Example**
```js ```js
function aysnFun(str1, str2) { function fun(num, callback) {
if (typeof str1 === 'object' && typeof str2 === 'object') { if (typeof num === 'number') {
return str2 callback(null, num + 3);
} else { } else {
return str1 callback("type err");
} }
} }
let newPromiseObj = util.promisify(aysnFun);
newPromiseObj({ err: "type error" }, {value:'HelloWorld'}).then(res => { const addCall = util.promisify(fun);
console.log(res); (async () => {
}) try {
let res = await addCall(2);
console.log(res);
} catch (err) {
console.log(err);
}
})();
``` ```
## util.randomUUID<sup>9+</sup> ## util.generateRandomUUID<sup>9+</sup>
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 **System capability**: SystemCapability.Utils.Lang
...@@ -162,17 +181,17 @@ Uses a secure random number generator to generate a random universally unique id ...@@ -162,17 +181,17 @@ Uses a secure random number generator to generate a random universally unique id
**Example** **Example**
```js ```js
let uuid = util.randomUUID(true); let uuid = util.generateRandomUUID(true);
console.log("RFC 4122 Version 4 UUID:" + uuid); console.log("RFC 4122 Version 4 UUID:" + uuid);
// Output: // Output:
// RFC 4122 Version 4 UUID:88368f2a-d5db-47d8-a05f-534fab0a0045 // RFC 4122 Version 4 UUID:88368f2a-d5db-47d8-a05f-534fab0a0045
``` ```
## util.randomBinaryUUID<sup>9+</sup> ## util.generateRandomBinaryUUID<sup>9+</sup>
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 **System capability**: SystemCapability.Utils.Lang
...@@ -191,7 +210,7 @@ Uses a secure random number generator to generate a random binary UUID of RFC 41 ...@@ -191,7 +210,7 @@ Uses a secure random number generator to generate a random binary UUID of RFC 41
**Example** **Example**
```js ```js
let uuid = util.randomBinaryUUID(true); let uuid = util.generateRandomBinaryUUID(true);
console.log(JSON.stringify(uuid)); console.log(JSON.stringify(uuid));
// Output: // Output:
// 138,188,43,243,62,254,70,119,130,20,235,222,199,164,140,150 // 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 ...@@ -201,7 +220,7 @@ Uses a secure random number generator to generate a random binary UUID of RFC 41
parseUUID(uuid: string): Uint8Array 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 **System capability**: SystemCapability.Utils.Lang
...@@ -243,7 +262,7 @@ Formats the specified values and inserts them into the string by replacing the w ...@@ -243,7 +262,7 @@ Formats the specified values and inserts them into the string by replacing the w
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| format | string | Yes| String.| | 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** **Return value**
...@@ -361,8 +380,8 @@ Creates a **TextDecoder** object. It provides the same function as the deprecate ...@@ -361,8 +380,8 @@ Creates a **TextDecoder** object. It provides the same function as the deprecate
**Example** **Example**
```js ```js
let textDecoder = new util.TextDecoder() let result = util.TextDecoder.create('utf-8', { ignoreBOM : true })
textDecoder.create('utf-8', { ignoreBOM : true }); let retStr = result.encoding
``` ```
### decodeWithStream<sup>9+</sup> ### decodeWithStream<sup>9+</sup>
...@@ -497,6 +516,7 @@ Decodes the input content. ...@@ -497,6 +516,7 @@ Decodes the input content.
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| encoding | string | Yes| No| Encoding format. The default format is **utf-8**.| | encoding | string | Yes| No| Encoding format. The default format is **utf-8**.|
### constructor ### constructor
constructor() constructor()
...@@ -1456,7 +1476,7 @@ Performs subsequent operations after a value is removed. ...@@ -1456,7 +1476,7 @@ Performs subsequent operations after a value is removed.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------- | ---- | ------------------------------------------------------------ | | -------- | ------- | ---- | ------------------------------------------------------------ |
| isEvict | boolean | Yes | Whether the cache capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity. | | isEvict | boolean | Yes | Whether the cache capacity is insufficient. If the value is **true**, this API is called due to insufficient capacity. |
| key | K | Yes | Key removed. | | key | K | Yes | Key removed. |
| value | V | Yes | Value removed. | | value | V | Yes | Value removed. |
| newValue | V | Yes | New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.| | newValue | V | Yes | New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.|
...@@ -3358,7 +3378,7 @@ A constructor used to create a **LruBuffer** instance. The default capacity of t ...@@ -3358,7 +3378,7 @@ A constructor used to create a **LruBuffer** instance. The default capacity of t
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.constructor<sup>9+</sup>](#constructor9-3) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3382,7 +3402,7 @@ Changes the **LruBuffer** capacity. If the new capacity is less than or equal to ...@@ -3382,7 +3402,7 @@ Changes the **LruBuffer** capacity. If the new capacity is less than or equal to
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [updateCapacity<sup>9+</sup>](#updatecapacity9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.updateCapacity<sup>9+</sup>](#updatecapacity9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3407,7 +3427,7 @@ Obtains the string representation of this **LruBuffer** object. ...@@ -3407,7 +3427,7 @@ Obtains the string representation of this **LruBuffer** object.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [toString<sup>9+</sup>](#tostring9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.toString<sup>9+</sup>](#tostring9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3435,7 +3455,7 @@ Obtains the capacity of this buffer. ...@@ -3435,7 +3455,7 @@ Obtains the capacity of this buffer.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCapacity<sup>9+</sup>](#getcapacity9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getCapacity<sup>9+</sup>](#getcapacity9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3459,7 +3479,7 @@ Clears key-value pairs from this buffer. The **afterRemoval()** method will be c ...@@ -3459,7 +3479,7 @@ Clears key-value pairs from this buffer. The **afterRemoval()** method will be c
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [clear<sup>9+</sup>](#clear9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.clear<sup>9+</sup>](#clear9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3480,7 +3500,7 @@ Obtains the number of return values for **createDefault()**. ...@@ -3480,7 +3500,7 @@ Obtains the number of return values for **createDefault()**.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCreateCount<sup>9+</sup>](#getcreatecount9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getCreateCount<sup>9+</sup>](#getcreatecount9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3506,7 +3526,7 @@ Obtains the number of times that the queried values are mismatched. ...@@ -3506,7 +3526,7 @@ Obtains the number of times that the queried values are mismatched.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getMissCount<sup>9+</sup>](#getmisscount9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getMissCount<sup>9+</sup>](#getmisscount9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3533,7 +3553,7 @@ Obtains the number of removals from this buffer. ...@@ -3533,7 +3553,7 @@ Obtains the number of removals from this buffer.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getRemovalCount<sup>9+</sup>](#getremovalcount9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getRemovalCount<sup>9+</sup>](#getremovalcount9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3561,7 +3581,7 @@ Obtains the number of times that the queried values are matched. ...@@ -3561,7 +3581,7 @@ Obtains the number of times that the queried values are matched.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getMatchCount<sup>9+</sup>](#getmatchcount9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getMatchCount<sup>9+</sup>](#getmatchcount9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3588,7 +3608,7 @@ Obtains the number of additions to this buffer. ...@@ -3588,7 +3608,7 @@ Obtains the number of additions to this buffer.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getPutCount<sup>9+</sup>](#getputcount9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getPutCount<sup>9+</sup>](#getputcount9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3614,7 +3634,7 @@ Checks whether this buffer is empty. ...@@ -3614,7 +3634,7 @@ Checks whether this buffer is empty.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [isEmpty<sup>9+</sup>](#isempty9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.isEmpty<sup>9+</sup>](#isempty9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3640,7 +3660,7 @@ Obtains the value of the specified key. ...@@ -3640,7 +3660,7 @@ Obtains the value of the specified key.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [get<sup>9+</sup>](#get9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.get<sup>9+</sup>](#get9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3672,7 +3692,7 @@ Adds a key-value pair to this buffer. ...@@ -3672,7 +3692,7 @@ Adds a key-value pair to this buffer.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [put<sup>9+</sup>](#put9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.put<sup>9+</sup>](#put9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3704,7 +3724,7 @@ Obtains all values in this buffer, listed from the most to the least recently ac ...@@ -3704,7 +3724,7 @@ Obtains all values in this buffer, listed from the most to the least recently ac
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [values<sup>9+</sup>](#values9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.values<sup>9+</sup>](#values9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3732,7 +3752,7 @@ Obtains all keys in this buffer, listed from the most to the least recently acce ...@@ -3732,7 +3752,7 @@ Obtains all keys in this buffer, listed from the most to the least recently acce
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [keys<sup>9+</sup>](#keys9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.keys<sup>9+</sup>](#keys9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3743,6 +3763,7 @@ Obtains all keys in this buffer, listed from the most to the least recently acce ...@@ -3743,6 +3763,7 @@ Obtains all keys in this buffer, listed from the most to the least recently acce
| K&nbsp;[] | All keys in the buffer, listed from the most to the least recently accessed.| | K&nbsp;[] | All keys in the buffer, listed from the most to the least recently accessed.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
...@@ -3757,7 +3778,7 @@ Removes the specified key and its value from this buffer. ...@@ -3757,7 +3778,7 @@ Removes the specified key and its value from this buffer.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [remove<sup>9+</sup>](#remove9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.remove<sup>9+</sup>](#remove9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3788,7 +3809,7 @@ Performs subsequent operations after a value is removed. ...@@ -3788,7 +3809,7 @@ Performs subsequent operations after a value is removed.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [afterRemoval<sup>9+</sup>](#afterremoval9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.afterRemoval<sup>9+</sup>](#afterremoval9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3796,7 +3817,7 @@ Performs subsequent operations after a value is removed. ...@@ -3796,7 +3817,7 @@ Performs subsequent operations after a value is removed.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| isEvict | boolean | Yes| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.| | isEvict | boolean | Yes| Whether the buffer capacity is insufficient. If the value is **true**, this API is called due to insufficient capacity.|
| key | K | Yes| Key removed.| | key | K | Yes| Key removed.|
| value | V | Yes| Value removed.| | value | V | Yes| Value removed.|
| newValue | V | Yes| New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.| | newValue | V | Yes| New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.|
...@@ -3832,7 +3853,7 @@ Checks whether this buffer contains the specified key. ...@@ -3832,7 +3853,7 @@ Checks whether this buffer contains the specified key.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [contains<sup>9+</sup>](#contains9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.contains<sup>9+</sup>](#contains9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3864,7 +3885,7 @@ Creates a value if the value of the specified key is not available. ...@@ -3864,7 +3885,7 @@ Creates a value if the value of the specified key is not available.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createDefault<sup>9+</sup>](#createdefault9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.createDefault<sup>9+</sup>](#createdefault9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3895,7 +3916,7 @@ Obtains a new iterator object that contains all key-value pairs in this object. ...@@ -3895,7 +3916,7 @@ Obtains a new iterator object that contains all key-value pairs in this object.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [entries<sup>9+</sup>](#entries9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.entries<sup>9+</sup>](#entries9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3921,7 +3942,7 @@ Obtains a two-dimensional array in key-value pairs. ...@@ -3921,7 +3942,7 @@ Obtains a two-dimensional array in key-value pairs.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Symbol.iterator<sup>9+</sup>](#symboliterator9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.Symbol.iterator<sup>9+</sup>](#symboliterator9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3953,7 +3974,7 @@ A constructor used to create a **Scope** object with the specified upper and low ...@@ -3953,7 +3974,7 @@ A constructor used to create a **Scope** object with the specified upper and low
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.constructor<sup>9+</sup>](#constructor9-4) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3980,7 +4001,7 @@ Obtains a string representation that contains this **Scope**. ...@@ -3980,7 +4001,7 @@ Obtains a string representation that contains this **Scope**.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [toString<sup>9+</sup>](#tostring9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.toString<sup>9+</sup>](#tostring9-1) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4007,7 +4028,7 @@ Obtains the intersection of this **Scope** and the given **Scope**. ...@@ -4007,7 +4028,7 @@ Obtains the intersection of this **Scope** and the given **Scope**.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [intersect<sup>9+</sup>](#intersect9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.intersect<sup>9+</sup>](#intersect9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4043,7 +4064,7 @@ Obtains the intersection of this **Scope** and the given lower and upper limits. ...@@ -4043,7 +4064,7 @@ Obtains the intersection of this **Scope** and the given lower and upper limits.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [intersect<sup>9+</sup>](#intersect9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.intersect<sup>9+</sup>](#intersect9-1) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4079,7 +4100,7 @@ Obtains the upper limit of this **Scope**. ...@@ -4079,7 +4100,7 @@ Obtains the upper limit of this **Scope**.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getUpper<sup>9+</sup>](#getupper9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.getUpper<sup>9+</sup>](#getupper9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4106,7 +4127,7 @@ Obtains the lower limit of this **Scope**. ...@@ -4106,7 +4127,7 @@ Obtains the lower limit of this **Scope**.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getLower<sup>9+</sup>](#getlower9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.getLower<sup>9+</sup>](#getlower9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4133,7 +4154,7 @@ Obtains the union set of this **Scope** and the given lower and upper limits. ...@@ -4133,7 +4154,7 @@ Obtains the union set of this **Scope** and the given lower and upper limits.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand<sup>9+</sup>](#expand9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.expand<sup>9+</sup>](#expand9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4169,7 +4190,7 @@ Obtains the union set of this **Scope** and the given **Scope**. ...@@ -4169,7 +4190,7 @@ Obtains the union set of this **Scope** and the given **Scope**.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand<sup>9+</sup>](#expand9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.expand<sup>9+</sup>](#expand9-1) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4205,7 +4226,7 @@ Obtains the union set of this **Scope** and the given value. ...@@ -4205,7 +4226,7 @@ Obtains the union set of this **Scope** and the given value.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand<sup>9+</sup>](#expand9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.expand<sup>9+</sup>](#expand9-2) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4239,7 +4260,7 @@ Checks whether a value is within this **Scope**. ...@@ -4239,7 +4260,7 @@ Checks whether a value is within this **Scope**.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [contains<sup>9+</sup>](#contains9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.contains<sup>9+</sup>](#contains9-1) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4273,7 +4294,7 @@ Checks whether a range is within this **Scope**. ...@@ -4273,7 +4294,7 @@ Checks whether a range is within this **Scope**.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [contains<sup>9+</sup>](#contains9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.contains<sup>9+</sup>](#contains9-2) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4310,7 +4331,7 @@ Limits a value to this **Scope**. ...@@ -4310,7 +4331,7 @@ Limits a value to this **Scope**.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [clamp<sup>9+</sup>](#clamp9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.clamp<sup>9+</sup>](#clamp9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4351,7 +4372,7 @@ A constructor used to create a **Base64** object. ...@@ -4351,7 +4372,7 @@ A constructor used to create a **Base64** object.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.constructor<sup>9+</sup>](#constructor9-5) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4369,7 +4390,7 @@ Encodes the input content. ...@@ -4369,7 +4390,7 @@ Encodes the input content.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeSync<sup>9+</sup>](#encodesync9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encodeSync<sup>9+</sup>](#encodesync9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4401,7 +4422,7 @@ Encodes the input content. ...@@ -4401,7 +4422,7 @@ Encodes the input content.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeToStringSync<sup>9+</sup>](#encodetostringsync9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encodeToStringSync<sup>9+</sup>](#encodetostringsync9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4433,7 +4454,7 @@ Decodes the input content. ...@@ -4433,7 +4454,7 @@ Decodes the input content.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [decodeSync<sup>9+</sup>](#decodesync9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.decodeSync<sup>9+</sup>](#decodesync9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4465,7 +4486,7 @@ Encodes the input content asynchronously. ...@@ -4465,7 +4486,7 @@ Encodes the input content asynchronously.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encode<sup>9+</sup>](#encode9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encode<sup>9+</sup>](#encode9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4502,7 +4523,7 @@ Encodes the input content asynchronously. ...@@ -4502,7 +4523,7 @@ Encodes the input content asynchronously.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeToString<sup>9+</sup>](#encodetostring9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encodeToString<sup>9+</sup>](#encodetostring9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4537,7 +4558,7 @@ Decodes the input content asynchronously. ...@@ -4537,7 +4558,7 @@ Decodes the input content asynchronously.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [decode<sup>9+</sup>](#decode9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.decode<sup>9+</sup>](#decode9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4565,5 +4586,3 @@ Decodes the input content asynchronously. ...@@ -4565,5 +4586,3 @@ Decodes the input content asynchronously.
} }
}) })
``` ```
<!--no_check-->
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册