提交 5b6c789f 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 48dd5d93
...@@ -21,18 +21,20 @@ For applications developed based on earlier versions, pay attention to the itera ...@@ -21,18 +21,20 @@ For applications developed based on earlier versions, pay attention to the itera
| medialibrary | **function** getAlbums(options: MediaFetchOptions): Promise&lt;Array&lt;Album&gt;&gt; | Interface compatibility changed | | medialibrary | **function** getAlbums(options: MediaFetchOptions): Promise&lt;Array&lt;Album&gt;&gt; | Interface compatibility changed |
| medialibrary | **function** FileAsset.commitModify(callback: AsyncCallback&lt;void&gt;): void | Interface compatibility changed | | medialibrary | **function** FileAsset.commitModify(callback: AsyncCallback&lt;void&gt;): void | Interface compatibility changed |
| medialibrary | **function** FileAsset.commitModify(): Promise&lt;void&gt; | Interface compatibility changed | | medialibrary | **function** FileAsset.commitModify(): Promise&lt;void&gt; | Interface compatibility changed |
| medialibrary | **function** FileAsset.deleteAsset(uri: string, callback: AsyncCallback&lt;void&gt;): void | Interface compatibility changed |
| medialibrary | **function** FileAsset.deleteAsset(uri: string): Promise&lt;void&gt; | Interface compatibility changed |
**Adaptation Guide** **Adaptation Guide**
**getFileAssets** **getFileAssets**
From API version 10, the albums represented by physical directories are replaced by logical albums, which allows multiple files in an album and presence of a file in multiple albums. This design, however, makes **parent**, **albumId**, **albumUri**, and **albumName** incompatible. They cannot be used as parameters of **MediaFetchOptions** in **getFileAssets()**. See the following example: From API version 10, the albums represented by physical directories are replaced by logical albums, which allow multiple files in an album and presence of a file in multiple albums. This design, however, makes **parent**, **albumId**, **albumUri**, and **albumName** incompatible. They cannot be used as parameters of **MediaFetchOptions** in **getFileAssets()**. The following is an example of incorrect use of the APIs.
1. Use [getMediaLibrary](../../../application-dev/reference/apis/js-apis-medialibrary.md#medialibrarygetmedialibrary) to obtain a **MediaLibrary** instance. 1. Call [getMediaLibrary](../../../application-dev/reference/apis/js-apis-medialibrary.md#medialibrarygetmedialibrary) to obtain a **MediaLibrary** instance.
2. Use [MediaFetchOptions](../../../application-dev/reference/apis/js-apis-medialibrary.md#mediafetchoptions7) to create the file fetching options. 2. Call [MediaFetchOptions](../../../application-dev/reference/apis/js-apis-medialibrary.md#mediafetchoptions7) to create the file fetching options.
3. Use [getFileAssets](../../../application-dev/reference/apis/js-apis-medialibrary.md#getfileassets7) to obtain file assets. 3. Call [getFileAssets](../../../application-dev/reference/apis/js-apis-medialibrary.md#getfileassets7) to obtain file assets.
**Incorrect code example**: **Example (incorrect)**:
```js ```js
import mediaLibrary from '@ohos.multimedia.mediaLibrary'; import mediaLibrary from '@ohos.multimedia.mediaLibrary';
...@@ -58,7 +60,7 @@ async function example() { ...@@ -58,7 +60,7 @@ async function example() {
Use **getFileAssets()** as follows: Use **getFileAssets()** as follows:
**Correct code example**: **Example (correct)**:
```js ```js
import mediaLibrary from '@ohos.multimedia.mediaLibrary'; import mediaLibrary from '@ohos.multimedia.mediaLibrary';
...@@ -84,17 +86,17 @@ async function example() { ...@@ -84,17 +86,17 @@ async function example() {
**createAsset** **createAsset**
From the SDK of API version 10, **relativePath** is no longer associated with an album. After a file is created, the last-level directory of **relativePath** is not displayed as an album. Since the SDK of API version 10, **relativePath** is no longer associated with an album. After a file is created, the last-level directory of **relativePath** is not displayed as an album.
**getAlbums** **getAlbums**
From the SDK of API version 10, **relativePath** is no longer associated with an album. Therefore, **relativePath** cannot be used as a search criterion in **getAlbums**, and the values of **ALBUM_NAME** can be **Camera** and **Screenshots** only. See the following example: Since the SDK of API version 10, **relativePath** is no longer associated with an album. Therefore, **relativePath** cannot be used as a search criterion in **getAlbums**, and the values of **ALBUM_NAME** can be **Camera** and **Screenshots** only. The following is an example of incorrect use of the APIs.
1. Use [getMediaLibrary](../../../application-dev/reference/apis/js-apis-medialibrary.md#medialibrarygetmedialibrary) to obtain a **MediaLibrary** instance. 1. Use [getMediaLibrary](../../../application-dev/reference/apis/js-apis-medialibrary.md#medialibrarygetmedialibrary) to obtain a **MediaLibrary** instance.
2. Use [MediaFetchOptions](../../../application-dev/reference/apis/js-apis-medialibrary.md#mediafetchoptions7) to create the album fetching options. 2. Use [MediaFetchOptions](../../../application-dev/reference/apis/js-apis-medialibrary.md#mediafetchoptions7) to create the album fetching options.
3. Use [getAlbums](../../../application-dev/reference/apis/js-apis-medialibrary.md#getalbums7) to obtain albums. 3. Use [getAlbums](../../../application-dev/reference/apis/js-apis-medialibrary.md#getalbums7) to obtain albums.
**Incorrect code example**: **Example (incorrect)**:
```js ```js
import mediaLibrary from '@ohos.multimedia.mediaLibrary'; import mediaLibrary from '@ohos.multimedia.mediaLibrary';
...@@ -119,7 +121,7 @@ async function example() { ...@@ -119,7 +121,7 @@ async function example() {
The following example shows how to obtain **Camera** and **Screenshots** albums: The following example shows how to obtain **Camera** and **Screenshots** albums:
**Correct code example**: **Example (correct)**:
```js ```js
import mediaLibrary from '@ohos.multimedia.mediaLibrary'; import mediaLibrary from '@ohos.multimedia.mediaLibrary';
...@@ -145,3 +147,40 @@ async function example() { ...@@ -145,3 +147,40 @@ async function example() {
**FileAsset.commitModify** **FileAsset.commitModify**
The **orientation** attribute for audio is deleted from the SDK of API version 10. When **commitModify** is used, the **orientation** attribute of audio resources cannot be modified. The **orientation** attribute for audio is deleted from the SDK of API version 10. When **commitModify** is used, the **orientation** attribute of audio resources cannot be modified.
**FileAsset.deleteAsset**
The change has resolved a known issue of the file deletion mechanism. This issue may cause a system application to permanently delete a file that is not in the trash using **MediaLibrary.deleteAsset**.
The correct procedure for a system application to permanently delete a file is as follows:
1. Call [getFileAssets](../../../application-dev/reference/apis/js-apis-medialibrary.md#getfileassets7) to obtain file assets.
2. Call [FileAsset.trash](../../../application-dev/reference/apis/js-apis-medialibrary.md#trash8) to move the file to the trash.
3. Call [MediaLibrary.deleteAsset](../../../application-dev/reference/apis/js-apis-medialibrary.md#deleteasset8) to permanently delete the file.
**Example (correct)**:
```js
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
async function example() {
try {
let context = getContext(this);
let media = mediaLibrary.getMediaLibrary(context);
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const fileAsset = await fetchFileResult.getFirstObject();
// Delete the file (move it to the trash of Gallery).
await fileAsset.trash(true);
// Delete the file from the system permanently.
await media.deleteAsset(fileAsset.uri);
} catch (err) {
console.error('Failed to delete asset permanently from system, error: ' + err);
}
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册