js-apis-medialibrary.md 110.5 KB
Newer Older
G
gloria 已提交
1
# @ohos.multimedia.medialibrary (Media Library Management)
W
wusongqing 已提交
2

W
wusongqing 已提交
3
> **NOTE**
G
Gloria 已提交
4
>
G
Gloria 已提交
5
> - The APIs of this module are supported since API version 6. Updates will be marked with a superscript to indicate their earliest API version.
A
Annie_wang 已提交
6
> - The APIs of this module are deprecated since API version 9. For details about the substitute APIs, see the API description.
W
wusongqing 已提交
7 8

## Modules to Import
A
Annie_wang 已提交
9

10
```js
W
wusongqing 已提交
11
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
W
wusongqing 已提交
12 13
```

W
wusongqing 已提交
14
## mediaLibrary.getMediaLibrary<sup>8+</sup>
W
wusongqing 已提交
15 16 17

getMediaLibrary(context: Context): MediaLibrary

W
wusongqing 已提交
18
Obtains a **MediaLibrary** instance, which is used to access and modify personal media data such as audios, videos, images, and documents.
W
wusongqing 已提交
19

20 21
This API can be used only in the stage model.

A
Annie_wang 已提交
22
> **NOTE**
A
Annie_wang 已提交
23
>
A
Annie_wang 已提交
24
> This API is deprecated since API version 9. Use [getPhotoAccessHelper](js-apis-photoAccessHelper.md#photoaccesshelpergetphotoaccesshelper) instead.
A
Annie_wang 已提交
25

W
wusongqing 已提交
26 27 28 29
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
30 31 32
| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
| context | Context | Yes  | Context of the ability.|
W
wusongqing 已提交
33 34 35

**Return value**

W
wusongqing 已提交
36 37
| Type                           | Description   |
| ----------------------------- | :---- |
A
Annie_wang 已提交
38
| [MediaLibrary](#medialibrary) | **MediaLibrary** instance obtained.|
W
wusongqing 已提交
39

W
wusongqing 已提交
40 41
**Example (from API version 9)**

42
```ts
G
Gloria 已提交
43
// Obtain a MediaLibrary instance. The instance obtained here is used in later.
44 45
const context = getContext(this);
let media = mediaLibrary.getMediaLibrary(context);
W
wusongqing 已提交
46 47
```

A
Annie_wang 已提交
48
**Example (from API version 8)**
W
wusongqing 已提交
49

50
```js
W
wusongqing 已提交
51 52
import featureAbility from '@ohos.ability.featureAbility';

53 54
let context = featureAbility.getContext();
let media = mediaLibrary.getMediaLibrary(context);
W
wusongqing 已提交
55
```
56

W
wusongqing 已提交
57 58 59 60 61 62
## mediaLibrary.getMediaLibrary

getMediaLibrary(): MediaLibrary

Obtains a **MediaLibrary** instance, which is used to access and modify personal media data such as audios, videos, images, and documents.

63 64
This API can be used only in the FA model.

A
Annie_wang 已提交
65
> **NOTE**
A
Annie_wang 已提交
66
>
A
Annie_wang 已提交
67
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
68

W
wusongqing 已提交
69 70 71 72 73 74
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

| Type                         | Description      |
| ----------------------------- | :--------- |
A
Annie_wang 已提交
75
| [MediaLibrary](#medialibrary) | **MediaLibrary** instance obtained.|
W
wusongqing 已提交
76 77 78 79

**Example**

```js
80
let media = mediaLibrary.getMediaLibrary();
W
wusongqing 已提交
81 82
```

W
wusongqing 已提交
83 84
## MediaLibrary

W
wusongqing 已提交
85
### getFileAssets<sup>7+</sup>
W
wusongqing 已提交
86 87 88 89 90

getFileAssets(options: MediaFetchOptions, callback: AsyncCallback&lt;FetchFileResult&gt;): void 

Obtains file assets (also called files). This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
91
> **NOTE**
A
Annie_wang 已提交
92
>
A
Annie_wang 已提交
93 94
> - This API is deprecated since API version 9. Use [getAssets](js-apis-photoAccessHelper.md#getassets) instead.
> - 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()**. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
A
Annie_wang 已提交
95

W
wusongqing 已提交
96 97 98 99 100 101
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
102 103 104
| Name  | Type                                               | Mandatory| Description                             |
| -------- | --------------------------------------------------- | ---- | --------------------------------- |
| options  | [MediaFetchOptions](#mediafetchoptions7)            | Yes  | Options for fetching the files.                     |
A
Annie_wang 已提交
105
| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | Yes  | Callback invoked to return the file retrieval result set.|
W
wusongqing 已提交
106 107 108

**Example**

109
```js
G
Gloria 已提交
110
async function example() {
A
Annie_wang 已提交
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  // Create options for fetching the files of the image type.
  let imagesFetchOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
  };
  // Obtain the files in asynchronous callback mode.
  media.getFileAssets(imagesFetchOp, async (error, fetchFileResult) => {
    // Check whether the result set of the obtained files is undefined. If yes, the API call fails.
    if (fetchFileResult == undefined) {
      console.error('get fetchFileResult failed with error: ' + error);
      return;
    }
    // Obtain the total number of files in the result set.
    const count = fetchFileResult.getCount();
    // Check whether the number is less than 0. If yes, the API call fails.
    if (count < 0) {
      console.error('get count from fetchFileResult failed, count: ' + count);
      return;
    }
    // Check whether the number is 0. If yes, the API call is successful, but the result set is empty. Check whether the options for fetching the files are correctly set and whether the corresponding files exist on the device.
    if (count == 0) {
      console.info('The count of fetchFileResult is zero');
      return;
    }
    console.info('Get fetchFileResult successfully, count: ' + count);
    // Obtain the first file in the result set in asynchronous callback mode. If there are a large number of files, use getAllObject() instead.
    fetchFileResult.getFirstObject(async (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++) {
        let fileAsset = await fetchFileResult.getNextObject();
        console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName);
      }
      // Release the FetchFileResult instance and invalidate it. Other APIs can no longer be called.
      fetchFileResult.close();
153
    });
A
Annie_wang 已提交
154
  });
G
Gloria 已提交
155
}
W
wusongqing 已提交
156
```
G
Gloria 已提交
157

W
wusongqing 已提交
158
### getFileAssets<sup>7+</sup>
W
wusongqing 已提交
159 160 161 162 163

getFileAssets(options: MediaFetchOptions): Promise&lt;FetchFileResult&gt;

Obtains file assets. This API uses a promise to return the result.

A
Annie_wang 已提交
164
> **NOTE**
A
Annie_wang 已提交
165
>
A
Annie_wang 已提交
166 167
> - This API is deprecated since API version 9. Use [getAssets](js-apis-photoAccessHelper.md#getassets-1) instead.
> - 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()**. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
A
Annie_wang 已提交
168

W
wusongqing 已提交
169 170 171 172 173 174
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
175 176 177
| Name | Type                                    | Mandatory| Description        |
| ------- | ---------------------------------------- | ---- | ------------ |
| options | [MediaFetchOptions](#mediafetchoptions7) | Yes  | Options for fetching the files.|
W
wusongqing 已提交
178 179 180

**Return value**

W
wusongqing 已提交
181 182
| Type                                | Description          |
| ------------------------------------ | -------------- |
A
Annie_wang 已提交
183
| Promise&lt;[FetchFileResult](#fetchfileresult7)&gt; | Promise used to return the file retrieval result set.|
W
wusongqing 已提交
184 185 186

**Example**

187
```js
G
Gloria 已提交
188
async function example() {
A
Annie_wang 已提交
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  // Create options for fetching the files of the image type.
  let imagesFetchOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
  };
  // Obtain the files in promise mode.
  media.getFileAssets(imagesFetchOp).then(async (fetchFileResult) => {
    // Obtain the total number of files in the result set.
    const count = fetchFileResult.getCount();
    // Check whether the number is less than 0. If yes, the API call fails.
    if (count < 0) {
      console.error('get count from fetchFileResult failed, count: ' + count);
      return;
    }
    // Check whether the number is 0. If yes, the API call is successful, but the result set is empty. Check whether the options for fetching the files are correctly set and whether the corresponding files exist on the device.
    if (count == 0) {
      console.info('The count of fetchFileResult is zero');
      return;
    }
    console.info('Get fetchFileResult successfully, count: ' + count);
    // Obtain the first file in the result set in promise mode. If there are a large number of files, use getAllObject instead.
    fetchFileResult.getFirstObject().then(async (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++) {
        let fileAsset = await fetchFileResult.getNextObject();
        console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName);
      }
      // Release the FetchFileResult instance and invalidate it. Other APIs can no longer be called.
      fetchFileResult.close();
G
Gloria 已提交
221
    }).catch((error) => {
A
Annie_wang 已提交
222 223
      // Calling getFirstObject fails.
      console.error('get first object failed with error: ' + error);
224
    });
A
Annie_wang 已提交
225 226 227 228
  }).catch((error) => {
    // Calling getFileAssets fails.
    console.error('get file assets failed with error: ' + error);
  });
G
Gloria 已提交
229
}
W
wusongqing 已提交
230 231 232 233
```

### on<sup>8+</sup>

G
gloria 已提交
234
on(type: 'deviceChange'&#124;'albumChange'&#124;'imageChange'&#124;'audioChange'&#124;'videoChange'&#124;'fileChange'&#124;'remoteFileChange', callback: Callback&lt;void&gt;): void
W
wusongqing 已提交
235

A
Annie_wang 已提交
236
Subscribes to the media library changes. This API uses a callback to return the result.
W
wusongqing 已提交
237

A
Annie_wang 已提交
238
> **NOTE**
A
Annie_wang 已提交
239 240
>
> This API is deprecated since API version 9. Use [registerChange](js-apis-photoAccessHelper.md#registerchange) instead.
A
Annie_wang 已提交
241

W
wusongqing 已提交
242 243 244 245
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
246 247
| Name     | Type                  | Mandatory  | Description                                      |
| -------- | -------------------- | ---- | ---------------------------------------- |
A
Annie_wang 已提交
248 249
| type     | 'deviceChange'&#124;<br>'albumChange'&#124;<br>'imageChange'&#124;<br>'audioChange'&#124;<br>'videoChange'&#124;<br>'fileChange'&#124;<br>'remoteFileChange'               | Yes   | Type of the event to subscribe to.<br>'deviceChange': registered device change<br>'albumChange': album change<br>'imageChange': image file change<br>'audioChange': audio file change<br>'videoChange': video file change<br>'fileChange': file change<br>'remoteFileChange': file change on the registered device|
| callback | Callback&lt;void&gt; | Yes   | Callback that returns no value.                                   |
W
wusongqing 已提交
250 251 252

**Example**

253
```js
W
wusongqing 已提交
254
media.on('imageChange', () => {
A
Annie_wang 已提交
255 256
  // image file had changed, do something.
});
W
wusongqing 已提交
257
```
A
Annie_wang 已提交
258

W
wusongqing 已提交
259 260
### off<sup>8+</sup>

G
gloria 已提交
261
off(type: 'deviceChange'&#124;'albumChange'&#124;'imageChange'&#124;'audioChange'&#124;'videoChange'&#124;'fileChange'&#124;'remoteFileChange', callback?: Callback&lt;void&gt;): void
W
wusongqing 已提交
262

A
Annie_wang 已提交
263
Unsubscribes from the media library changes. This API uses a callback to return the result.
W
wusongqing 已提交
264

A
Annie_wang 已提交
265
> **NOTE**
A
Annie_wang 已提交
266 267
>
> This API is deprecated since API version 9. Use [unRegisterChange](js-apis-photoAccessHelper.md#unregisterchange) instead.
A
Annie_wang 已提交
268

W
wusongqing 已提交
269 270 271 272
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
273 274
| Name     | Type                  | Mandatory  | Description                                      |
| -------- | -------------------- | ---- | ---------------------------------------- |
A
Annie_wang 已提交
275 276
| type     | 'deviceChange'&#124;<br>'albumChange'&#124;<br>'imageChange'&#124;<br>'audioChange'&#124;<br>'videoChange'&#124;<br>'fileChange'&#124;<br>'remoteFileChange'               | Yes   | Type of the event to unsubscribe from.<br>'deviceChange': registered device change<br>'albumChange': album change<br>'imageChange': image file change<br>'audioChange': audio file change<br>'videoChange': video file change<br>'fileChange': file change<br>'remoteFileChange': file change on the registered device|
| callback | Callback&lt;void&gt; | No   | Callback that returns no value.                                   |
W
wusongqing 已提交
277 278 279

**Example**

280
```js
W
wusongqing 已提交
281
media.off('imageChange', () => {
A
Annie_wang 已提交
282 283
  // stop listening successfully.
});
W
wusongqing 已提交
284 285
```

286
### createAsset<sup>8+</sup>
W
wusongqing 已提交
287 288 289 290 291

createAsset(mediaType: MediaType, displayName: string, relativePath: string, callback: AsyncCallback&lt;FileAsset&gt;): void

Creates a media asset. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
292
> **NOTE**
A
Annie_wang 已提交
293
>
A
Annie_wang 已提交
294
> - This API is deprecated since API version 9. Use [createAsset](js-apis-photoAccessHelper.md#createasset) instead.
A
Annie_wang 已提交
295
> - 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. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
A
Annie_wang 已提交
296

W
wusongqing 已提交
297 298 299 300 301 302
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
303 304 305
| Name      | Type                                   | Mandatory| Description                                                        |
| ------------ | --------------------------------------- | ---- | ------------------------------------------------------------ |
| mediaType    | [MediaType](#mediatype8)                | Yes  | Media type.                                                    |
A
Annie_wang 已提交
306 307 308
| displayName  | string                                  | Yes  | File name to display.                                                  |
| relativePath | string                                  | Yes  | Path of the file, which can be obtained by using [getPublicDirectory](#getpublicdirectory8).|
| callback     | AsyncCallback<[FileAsset](#fileasset7)> | Yes  | Callback invoked to return the **FileAsset** instance created.                         |
W
wusongqing 已提交
309 310 311

**Example**

312
```js
W
wusongqing 已提交
313
async function example() {
A
Annie_wang 已提交
314 315 316 317 318 319 320 321 322 323 324
  // Create an image file in callback mode.
  let mediaType = mediaLibrary.MediaType.IMAGE;
  let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
  const path = await media.getPublicDirectory(DIR_IMAGE);
  media.createAsset(mediaType, 'imageCallBack.jpg', path + 'myPicture/', (error, fileAsset) => {
    if (fileAsset != undefined) {
      console.info('createAsset successfully, message');
    } else {
      console.error('createAsset failed with error: ' + error);
    }
  });
W
wusongqing 已提交
325 326 327 328 329 330 331 332 333
}
```

### createAsset<sup>8+</sup>

createAsset(mediaType: MediaType, displayName: string, relativePath: string): Promise&lt;FileAsset&gt;

Creates a media asset. This API uses a promise to return the result.

A
Annie_wang 已提交
334
> **NOTE**
A
Annie_wang 已提交
335
>
A
Annie_wang 已提交
336
> - This API is deprecated since API version 9. Use [createAsset](js-apis-photoAccessHelper.md#createasset-1) instead.
A
Annie_wang 已提交
337
> - 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. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
A
Annie_wang 已提交
338

W
wusongqing 已提交
339 340 341 342 343 344
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
345 346 347
| Name      | Type                    | Mandatory| Description                                                        |
| ------------ | ------------------------ | ---- | ------------------------------------------------------------ |
| mediaType    | [MediaType](#mediatype8) | Yes  | Media type.                                                    |
A
Annie_wang 已提交
348
| displayName  | string                   | Yes  | File name to display.                                                  |
A
Annie_wang 已提交
349
| relativePath | string                   | Yes  | Relative path of the file, which can be obtained by **getPublicDirectory**.|
W
wusongqing 已提交
350 351 352

**Return value**

W
wusongqing 已提交
353 354
| Type                    | Description             |
| ------------------------ | ----------------- |
A
Annie_wang 已提交
355
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the **FileAsset** instance created.|
W
wusongqing 已提交
356 357 358

**Example**

359
```js
360
async function example() {
A
Annie_wang 已提交
361 362 363 364 365 366 367 368 369
  // Create an image file in promise mode.
  let mediaType = mediaLibrary.MediaType.IMAGE;
  let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
  const path = await media.getPublicDirectory(DIR_IMAGE);
  media.createAsset(mediaType, 'imagePromise.jpg', path + 'myPicture/').then((fileAsset) => {
    console.info('createAsset successfully, message = ' + JSON.stringify(fileAsset));
  }).catch((error) => {
    console.error('createAsset failed with error: ' + error);
  });
370
}
W
wusongqing 已提交
371 372
```

373 374 375 376 377 378
### deleteAsset<sup>8+</sup>

deleteAsset(uri: string): Promise\<void>

Deletes a file asset. This API uses a promise to return the result.

A
Annie_wang 已提交
379 380 381
Before calling this API, call [FileAsset.trash](#trash8) to move the file to the trash. Otherwise, the file fails to be deleted.

> **NOTE**
A
Annie_wang 已提交
382 383
>
> This API is deprecated since API version 9. Use [deleteAssets](js-apis-photoAccessHelper.md#deleteassets-3) instead.
A
Annie_wang 已提交
384

385 386 387 388 389 390 391 392 393 394 395 396 397
**System API**: This is a system API.

**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

| Name     | Type                          | Mandatory  | Description             |
| -------- | ---------------------------- | ---- | --------------- |
| uri | string | Yes   | URI of the file asset to delete.|

**Return value**
A
Annie_wang 已提交
398

399 400 401 402 403 404 405 406
| Type                 | Description                  |
| ------------------- | -------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**

```js
async function example() {
A
Annie_wang 已提交
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
  let fileKeyObj = mediaLibrary.FileKey;
  let fileType = mediaLibrary.MediaType.FILE;
  let option = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [fileType.toString()],
  };
  const fetchFileResult = await media.getFileAssets(option);
  let asset = await fetchFileResult.getFirstObject();
  if (asset == undefined) {
    console.error('asset not exist');
    return;
  }
  media.deleteAsset(asset.uri).then(() => {
    console.info('deleteAsset successfully');
  }).catch((error) => {
    console.error('deleteAsset failed with error: ' + error);
  });
  fetchFileResult.close();
425 426 427 428
}
```

### deleteAsset<sup>8+</sup>
A
Annie_wang 已提交
429

430 431 432 433
deleteAsset(uri: string, callback: AsyncCallback\<void>): void

Deletes a file asset. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
434 435 436
Before calling this API, call [FileAsset.trash](#trash8) to move the file to the trash. Otherwise, the file fails to be deleted.

> **NOTE**
A
Annie_wang 已提交
437 438
>
> This API is deprecated since API version 9. Use [deleteAssets](js-apis-photoAccessHelper.md#deleteassets-2) instead.
A
Annie_wang 已提交
439

440 441 442 443 444 445 446 447 448 449 450
**System API**: This is a system API.

**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

| Name     | Type                          | Mandatory  | Description             |
| -------- | ---------------------------- | ---- | --------------- |
| uri | string | Yes   | URI of the file asset to delete.|
A
Annie_wang 已提交
451
|callback |AsyncCallback\<void>| Yes |Callback that returns no value.|
452 453 454 455 456

**Example**

```js
async function example() {
A
Annie_wang 已提交
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
  let fileKeyObj = mediaLibrary.FileKey;
  let fileType = mediaLibrary.MediaType.FILE;
  let option = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [fileType.toString()],
  };
  const fetchFileResult = await media.getFileAssets(option);
  let asset = await fetchFileResult.getFirstObject();
  if (asset == undefined) {
    console.error('asset not exist');
    return;
  }
  media.deleteAsset(asset.uri, (error) => {
    if (error != undefined) {
      console.error('deleteAsset failed with error: ' + error);
    } else {
      console.info('deleteAsset successfully');
474
    }
A
Annie_wang 已提交
475 476
  });
  fetchFileResult.close();
477 478 479
}
```

W
wusongqing 已提交
480 481 482 483
### getPublicDirectory<sup>8+</sup>

getPublicDirectory(type: DirectoryType, callback: AsyncCallback&lt;string&gt;): void

A
Annie_wang 已提交
484
Obtains a user directory. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
485

A
Annie_wang 已提交
486
> **NOTE**
A
Annie_wang 已提交
487 488
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
489

W
wusongqing 已提交
490 491 492 493
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
494 495
| Name  | Type                            | Mandatory| Description                     |
| -------- | -------------------------------- | ---- | ------------------------- |
A
Annie_wang 已提交
496 497
| type     | [DirectoryType](#directorytype8) | Yes  | Type of the user directory.             |
| callback | AsyncCallback&lt;string&gt;      | Yes  | Callback invoked to return the user directory obtained.|
W
wusongqing 已提交
498 499 500

**Example**

501
```js
W
wusongqing 已提交
502
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
G
Gloria 已提交
503
media.getPublicDirectory(DIR_CAMERA, (error, dicResult) => {
A
Annie_wang 已提交
504 505 506 507 508
  if (dicResult == 'Camera/') {
    console.info('getPublicDirectory DIR_CAMERA successfully');
  } else {
    console.error('getPublicDirectory DIR_CAMERA failed with error: ' + error);
  }
W
wusongqing 已提交
509 510 511 512 513 514 515
});
```

### getPublicDirectory<sup>8+</sup>

getPublicDirectory(type: DirectoryType): Promise&lt;string&gt;

A
Annie_wang 已提交
516
Obtains a user directory. This API uses a promise to return the result.
W
wusongqing 已提交
517

A
Annie_wang 已提交
518
> **NOTE**
A
Annie_wang 已提交
519 520
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
521

W
wusongqing 已提交
522 523 524 525
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
526 527
| Name| Type                            | Mandatory| Description        |
| ------ | -------------------------------- | ---- | ------------ |
A
Annie_wang 已提交
528
| type   | [DirectoryType](#directorytype8) | Yes  | Type of the user directory.|
W
wusongqing 已提交
529 530 531

**Return value**

W
wusongqing 已提交
532 533
| Type            | Description            |
| ---------------- | ---------------- |
A
Annie_wang 已提交
534
| Promise\<string> | Promise used to return the user directory obtained.|
W
wusongqing 已提交
535 536 537

**Example**

538
```js
W
wusongqing 已提交
539
async function example() {
A
Annie_wang 已提交
540 541 542 543 544 545 546 547 548 549
  let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
  media.getPublicDirectory(DIR_CAMERA).then((dicResult) => {
    if (dicResult == 'Camera/') {
      console.info('getPublicDirectory DIR_CAMERA successfully');
    } else {
      console.error('getPublicDirectory DIR_CAMERA failed');
    }
  }).catch((error) => {
    console.error('getPublicDirectory failed with error: ' + error);
  });
W
wusongqing 已提交
550 551 552
}
```

W
wusongqing 已提交
553
### getAlbums<sup>7+</sup>
W
wusongqing 已提交
554

G
Gloria 已提交
555
getAlbums(options: MediaFetchOptions, callback: AsyncCallback&lt;Array&lt;Album&gt;&gt;): void
W
wusongqing 已提交
556

A
Annie_wang 已提交
557 558 559
Obtains albums. This API uses an asynchronous callback to return the result.

> **NOTE**
A
Annie_wang 已提交
560
>
A
Annie_wang 已提交
561
> - This API is deprecated since API version 9. Use [getAlbums](js-apis-photoAccessHelper.md#getalbums) instead.
A
Annie_wang 已提交
562
> - 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**. Currently, only **Camera** and **ScreenShots** albums are supported. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
W
wusongqing 已提交
563 564 565 566 567 568 569

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
570 571
| Name  | Type                                        | Mandatory| Description                       |
| -------- | -------------------------------------------- | ---- | --------------------------- |
A
Annie_wang 已提交
572 573
| options  | [MediaFetchOptions](#mediafetchoptions7)     | Yes  | Options for fetching albums.               |
| callback | AsyncCallback&lt;Array<[Album](#album7)>&gt; | Yes  | Callback invoked to return the albums.|
W
wusongqing 已提交
574 575 576

**Example**

577
```js
G
Gloria 已提交
578
async function example() {
579 580
  let AlbumNoArgsfetchOp = {
    selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
A
Annie_wang 已提交
581
    selectionArgs: ['Camera'],
582 583 584 585 586 587 588
  };
  media.getAlbums(AlbumNoArgsfetchOp, (error, albumList) => {
    if (albumList != undefined) {
      console.info('getAlbums successfully: ' + JSON.stringify(albumList));
    } else {
      console.error('getAlbums failed with error: ' + error);
    }
A
Annie_wang 已提交
589
  });
G
Gloria 已提交
590
}
W
wusongqing 已提交
591 592
```

W
wusongqing 已提交
593
### getAlbums<sup>7+</sup>
W
wusongqing 已提交
594

G
Gloria 已提交
595
getAlbums(options: MediaFetchOptions): Promise&lt;Array&lt;Album&gt;&gt;
W
wusongqing 已提交
596

A
Annie_wang 已提交
597 598 599
Obtains albums. This API uses a promise to return the result.

> **NOTE**
A
Annie_wang 已提交
600
>
A
Annie_wang 已提交
601
> - This API is deprecated since API version 9. Use [getAlbums](js-apis-photoAccessHelper.md#getalbums-2) instead.
A
Annie_wang 已提交
602
> - 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**. Currently, only **Camera** and **ScreenShots** albums are supported. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
W
wusongqing 已提交
603 604 605 606 607 608 609

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
610 611 612
| Name | Type                                    | Mandatory| Description        |
| ------- | ---------------------------------------- | ---- | ------------ |
| options | [MediaFetchOptions](#mediafetchoptions7) | Yes  | Options for fetching the albums.|
W
wusongqing 已提交
613 614 615

**Return value**

W
wusongqing 已提交
616 617 618
| Type                            | Description         |
| -------------------------------- | ------------- |
| Promise<Array<[Album](#album7)>> | Promise used to return the albums.|
W
wusongqing 已提交
619 620 621

**Example**

622
```js
G
Gloria 已提交
623
async function example() {
624 625
  let AlbumNoArgsfetchOp = {
    selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
A
Annie_wang 已提交
626
    selectionArgs: ['Camera'],
627 628 629 630 631 632
  };
  media.getAlbums(AlbumNoArgsfetchOp).then((albumList) => {
    console.info('getAlbums successfully: ' + JSON.stringify(albumList));
  }).catch((error) => {
    console.error('getAlbums failed with error: ' + error);
  });
G
Gloria 已提交
633
}
W
wusongqing 已提交
634 635 636 637 638 639 640 641 642
```

### release<sup>8+</sup>

release(callback: AsyncCallback&lt;void&gt;): void

Releases this **MediaLibrary** instance.
Call this API when you no longer need to use the APIs in the **MediaLibrary** instance.

A
Annie_wang 已提交
643
> **NOTE**
A
Annie_wang 已提交
644 645
>
> This API is deprecated since API version 9. Use [release](js-apis-photoAccessHelper.md#release) instead.
A
Annie_wang 已提交
646

W
wusongqing 已提交
647 648 649 650
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
651 652
| Name     | Type                       | Mandatory  | Description        |
| -------- | ------------------------- | ---- | ---------- |
G
Gloria 已提交
653
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.|
W
wusongqing 已提交
654 655 656

**Example**

657
```js
G
Gloria 已提交
658
media.release(() => {
A
Annie_wang 已提交
659
  // do something.
W
wusongqing 已提交
660 661 662 663 664 665 666 667 668 669
});
```

### release<sup>8+</sup>

release(): Promise&lt;void&gt;

Releases this **MediaLibrary** instance.
Call this API when you no longer need to use the APIs in the **MediaLibrary** instance.

A
Annie_wang 已提交
670
> **NOTE**
A
Annie_wang 已提交
671
>
A
Annie_wang 已提交
672
> This API is deprecated since API version 9. Use [release](js-apis-photoAccessHelper.md#release-1) instead.
A
Annie_wang 已提交
673

W
wusongqing 已提交
674 675 676 677
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
678 679
| Type                 | Description                  |
| ------------------- | -------------------- |
A
Annie_wang 已提交
680
| Promise&lt;void&gt; | Promise that returns no value.|
W
wusongqing 已提交
681 682 683

**Example**

684
```js
A
Annie_wang 已提交
685
media.release();
W
wusongqing 已提交
686 687
```

G
Gloria 已提交
688
### storeMediaAsset
W
wusongqing 已提交
689 690 691

storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback&lt;string&gt;): void

A
Annie_wang 已提交
692
Stores a media asset. This API uses an asynchronous callback to return the URI of the media asset.
W
wusongqing 已提交
693

A
Annie_wang 已提交
694 695 696
> **NOTE**
>
> - This API is supported since API version 6 and can be used only in the FA model.
A
Annie_wang 已提交
697
> - This API is deprecated since API version 9. Use [save](js-apis-file-picker.md#save-1) instead.
W
wusongqing 已提交
698 699 700 701 702

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
703 704 705
| Name     | Type                                   | Mandatory  | Description                     |
| -------- | ------------------------------------- | ---- | ----------------------- |
| option   | [MediaAssetOption](#mediaassetoption) | Yes   | Media asset option.                |
A
Annie_wang 已提交
706
| callback | AsyncCallback&lt;string&gt;           | Yes   | Callback invoked to return the URI of the media resource saved.|
W
wusongqing 已提交
707 708 709

**Example**

710
```js
W
wusongqing 已提交
711
let option = {
A
Annie_wang 已提交
712 713 714
  src : '/data/storage/el2/base/haps/entry/image.png',
  mimeType : 'image/*',
  relativePath : 'Pictures/'
W
wusongqing 已提交
715
};
G
Gloria 已提交
716
mediaLibrary.getMediaLibrary().storeMediaAsset(option, (error, value) => {
A
Annie_wang 已提交
717 718 719 720 721 722
  if (error) {
    console.error('storeMediaAsset failed with error: ' + error);
    return;
  }
  console.info('Media resources stored. ');
  // Obtain the URI of the media asset.
W
wusongqing 已提交
723
});
724
```
W
wusongqing 已提交
725

G
Gloria 已提交
726
### storeMediaAsset
W
wusongqing 已提交
727 728 729

storeMediaAsset(option: MediaAssetOption): Promise&lt;string&gt;

A
Annie_wang 已提交
730
Stores a media asset. This API uses a promise to return the URI of the media asset.
W
wusongqing 已提交
731

A
Annie_wang 已提交
732 733 734
> **NOTE**
>
> - This API is supported since API version 6 and can be used only in the FA model.
A
Annie_wang 已提交
735
> - This API is deprecated since API version 9. Use [save](js-apis-file-picker.md#save) instead.
W
wusongqing 已提交
736 737 738 739 740

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
741 742 743
| Name   | Type                                   | Mandatory  | Description     |
| ------ | ------------------------------------- | ---- | ------- |
| option | [MediaAssetOption](#mediaassetoption) | Yes   | Media asset option.|
W
wusongqing 已提交
744 745 746

**Return value**

W
wusongqing 已提交
747 748
| Type                   | Description                          |
| --------------------- | ---------------------------- |
A
Annie_wang 已提交
749
| Promise&lt;string&gt; | Promise used to return the URI of the media asset saved.|
W
wusongqing 已提交
750 751 752

**Example**

753
```js
W
wusongqing 已提交
754
let option = {
A
Annie_wang 已提交
755 756 757
  src : '/data/storage/el2/base/haps/entry/image.png',
  mimeType : 'image/*',
  relativePath : 'Pictures/'
W
wusongqing 已提交
758 759
};
mediaLibrary.getMediaLibrary().storeMediaAsset(option).then((value) => {
A
Annie_wang 已提交
760 761
  console.info('Media resources stored.');
  // Obtain the URI of the media asset.
G
Gloria 已提交
762
}).catch((error) => {
A
Annie_wang 已提交
763
  console.error('storeMediaAsset failed with error: ' + error);
W
wusongqing 已提交
764
});
765
```
W
wusongqing 已提交
766

G
Gloria 已提交
767
### startImagePreview
W
wusongqing 已提交
768 769 770

startImagePreview(images: Array&lt;string&gt;, index: number, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
771
Starts image preview, with the first image to preview specified. This API can be used to preview a local image with the specified index (**file://**) or all online images (**https://**). It uses an asynchronous callback to return the result.
W
wusongqing 已提交
772

W
wusongqing 已提交
773
> **NOTE**
A
Annie_wang 已提交
774 775
>
> - This API is supported since API version 6 and can be used only in the FA model.
A
Annie_wang 已提交
776
> - This API is deprecated since API version 9. You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead. <br>The **\<Image>** component can be used to render and display local and online images.
W
wusongqing 已提交
777 778 779 780 781

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
782 783
| Name     | Type                       | Mandatory  | Description                                      |
| -------- | ------------------------- | ---- | ---------------------------------------- |
A
Annie_wang 已提交
784
| images   | Array&lt;string&gt;       | Yes   | Images to preview. You can preview a local image (**file://**) or all online images (**https://**).|
W
wusongqing 已提交
785
| index    | number                    | Yes   | Index of the first image to preview.                              |
A
Annie_wang 已提交
786
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.                       |
W
wusongqing 已提交
787 788 789

**Example**

790
```js
W
wusongqing 已提交
791
let images = [
A
Annie_wang 已提交
792 793
  'file://media/xxxx/2',
  'file://media/xxxx/3'
W
wusongqing 已提交
794
];
W
wusongqing 已提交
795
/* Preview online images.
W
wusongqing 已提交
796
let images = [
A
Annie_wang 已提交
797 798
  'https://media.xxxx.com/image1.jpg',
  'https://media.xxxx.com/image2.jpg'
W
wusongqing 已提交
799
];
W
wusongqing 已提交
800
*/
W
wusongqing 已提交
801
let index = 1;
G
Gloria 已提交
802
mediaLibrary.getMediaLibrary().startImagePreview(images, index, (error) => {
A
Annie_wang 已提交
803 804 805 806 807
  if (error) {
    console.error('startImagePreview failed with error: ' + error);
    return;
  }
  console.info('Succeeded in previewing the images.');
W
wusongqing 已提交
808
});
809
```
W
wusongqing 已提交
810

G
Gloria 已提交
811
### startImagePreview
W
wusongqing 已提交
812 813 814

startImagePreview(images: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
815
Starts image preview. This API can be used to preview the first local image (**file://**) or all online images (**https://**). It uses an asynchronous callback to return the result.
W
wusongqing 已提交
816

W
wusongqing 已提交
817
> **NOTE**
A
Annie_wang 已提交
818 819
>
> - This API is supported since API version 6 and can be used only in the FA model.
A
Annie_wang 已提交
820
> - This API is deprecated since API version 9. You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead. <br>The **\<Image>** component can be used to render and display local and online images.
W
wusongqing 已提交
821 822 823 824 825

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
826 827
| Name     | Type                       | Mandatory  | Description                                      |
| -------- | ------------------------- | ---- | ---------------------------------------- |
A
Annie_wang 已提交
828
| images   | Array&lt;string&gt;       | Yes   | Images to preview. You can preview a local image (**file://**) or all online images (**https://**).|
A
Annie_wang 已提交
829
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.                       |
W
wusongqing 已提交
830 831 832

**Example**

833
```js
W
wusongqing 已提交
834
let images = [
A
Annie_wang 已提交
835 836
  'file://media/xxxx/2',
  'file://media/xxxx/3'
W
wusongqing 已提交
837
];
W
wusongqing 已提交
838
/* Preview online images.
W
wusongqing 已提交
839
let images = [
A
Annie_wang 已提交
840 841
  'https://media.xxxx.com/image1.jpg',
  'https://media.xxxx.com/image2.jpg'
W
wusongqing 已提交
842
];
W
wusongqing 已提交
843
*/
G
Gloria 已提交
844
mediaLibrary.getMediaLibrary().startImagePreview(images, (error) => {
A
Annie_wang 已提交
845 846 847 848 849
  if (error) {
    console.error('startImagePreview failed with error: ' + error);
    return;
  }
  console.info('Succeeded in previewing the images.');
W
wusongqing 已提交
850
});
851
```
W
wusongqing 已提交
852

G
Gloria 已提交
853
### startImagePreview
W
wusongqing 已提交
854 855 856

startImagePreview(images: Array&lt;string&gt;, index?: number): Promise&lt;void&gt;

A
Annie_wang 已提交
857
Starts image preview, with the first image to preview specified. This API can be used to preview a local image with the specified index (**file://**) or all online images (**https://**). It uses a promise to return the execution result.
W
wusongqing 已提交
858

W
wusongqing 已提交
859
> **NOTE**
A
Annie_wang 已提交
860 861
>
> - This API is supported since API version 6 and can be used only in the FA model.
A
Annie_wang 已提交
862
> - This API is deprecated since API version 9. You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead. <br>The **\<Image>** component can be used to render and display local and online images.
W
wusongqing 已提交
863 864 865 866 867

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
868 869
| Name   | Type                 | Mandatory  | Description                                      |
| ------ | ------------------- | ---- | ---------------------------------------- |
A
Annie_wang 已提交
870
| images | Array&lt;string&gt; | Yes   | Images to preview. You can preview a local image (**file://**) or all online images (**https://**).|
W
wusongqing 已提交
871
| index  | number              | No   | Index of the first image to preview. If this parameter is not specified, the default value **0** is used.                     |
W
wusongqing 已提交
872 873 874

**Return value**

W
wusongqing 已提交
875 876
| Type                 | Description                             |
| ------------------- | ------------------------------- |
A
Annie_wang 已提交
877
| Promise&lt;void&gt; | Promise that returns no value.|
W
wusongqing 已提交
878 879 880

**Example**

881
```js
W
wusongqing 已提交
882
let images = [
A
Annie_wang 已提交
883 884
  'file://media/xxxx/2',
  'file://media/xxxx/3'
W
wusongqing 已提交
885
];
W
wusongqing 已提交
886
/* Preview online images.
W
wusongqing 已提交
887
let images = [
A
Annie_wang 已提交
888 889
  'https://media.xxxx.com/image1.jpg',
  'https://media.xxxx.com/image2.jpg'
W
wusongqing 已提交
890
];
W
wusongqing 已提交
891
*/
W
wusongqing 已提交
892 893
let index = 1;
mediaLibrary.getMediaLibrary().startImagePreview(images, index).then(() => {
A
Annie_wang 已提交
894
  console.info('Succeeded in previewing the images.');
G
Gloria 已提交
895
}).catch((error) => {
A
Annie_wang 已提交
896
  console.error('startImagePreview failed with error: ' + error);
W
wusongqing 已提交
897
});
898
```
W
wusongqing 已提交
899

G
Gloria 已提交
900
### startMediaSelect
W
wusongqing 已提交
901 902 903

startMediaSelect(option: MediaSelectOption, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void

A
Annie_wang 已提交
904
Starts media selection. This API uses an asynchronous callback to return the URIs of the selected media assets.
W
wusongqing 已提交
905

W
wusongqing 已提交
906
> **NOTE**
A
Annie_wang 已提交
907 908
>
> - This API is supported since API version 6 and can be used only in the FA model.
A
Annie_wang 已提交
909
> - This API is deprecated since API version 9. Use [select](js-apis-file-picker.md#select-1) instead.
W
wusongqing 已提交
910 911 912 913 914

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
915 916
| Name     | Type                                      | Mandatory  | Description                                  |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
G
Gloria 已提交
917
| option   | [MediaSelectOption](#mediaselectoption)  | Yes   | Media selection option.                             |
A
Annie_wang 已提交
918
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback invoked to return the URIs of the selected media assets.|
W
wusongqing 已提交
919 920 921

**Example**

922 923
```js
let option : mediaLibrary.MediaSelectOption = {
A
Annie_wang 已提交
924 925
  type : 'media',
  count : 2
W
wusongqing 已提交
926
};
G
Gloria 已提交
927
mediaLibrary.getMediaLibrary().startMediaSelect(option, (error, value) => {
A
Annie_wang 已提交
928 929 930 931 932 933
  if (error) {
    console.error('startMediaSelect failed with error: ' + error);
    return;
  }
  console.info('Media resources selected.');
  // Obtain the media selection value.
W
wusongqing 已提交
934
});
935
```
W
wusongqing 已提交
936

G
Gloria 已提交
937
### startMediaSelect
W
wusongqing 已提交
938 939 940

startMediaSelect(option: MediaSelectOption): Promise&lt;Array&lt;string&gt;&gt;

A
Annie_wang 已提交
941
Starts media selection. This API uses a promise to return the URIs of the selected media assets.
W
wusongqing 已提交
942

W
wusongqing 已提交
943
> **NOTE**
A
Annie_wang 已提交
944 945
>
> - This API is supported since API version 6 and can be used only in the FA model.
A
Annie_wang 已提交
946
> - This API is deprecated since API version 9. Use [select](js-apis-file-picker.md#select) instead.
W
wusongqing 已提交
947 948 949 950 951

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
952 953
| Name   | Type                                     | Mandatory  | Description     |
| ------ | --------------------------------------- | ---- | ------- |
G
Gloria 已提交
954
| option | [MediaSelectOption](#mediaselectoption) | Yes   | Media selection option.|
W
wusongqing 已提交
955 956 957

**Return value**

W
wusongqing 已提交
958 959
| Type                                | Description                                      |
| ---------------------------------- | ---------------------------------------- |
A
Annie_wang 已提交
960
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the URIs of the selected media assets.|
W
wusongqing 已提交
961 962 963

**Example**

964 965
```js
let option : mediaLibrary.MediaSelectOption = {
A
Annie_wang 已提交
966 967
  type : 'media',
  count : 2
W
wusongqing 已提交
968 969
};
mediaLibrary.getMediaLibrary().startMediaSelect(option).then((value) => {
A
Annie_wang 已提交
970 971
  console.info('Media resources selected.');
  // Obtain the media selection value.
G
Gloria 已提交
972
}).catch((error) => {
A
Annie_wang 已提交
973
  console.error('startMediaSelect failed with error: ' + error);
W
wusongqing 已提交
974
});
975
```
A
Annie_wang 已提交
976

977 978 979 980 981 982
### getActivePeers<sup>8+</sup>

getActivePeers(): Promise\<Array\<PeerInfo>>;

Obtains information about online peer devices. This API uses a promise to return the result.

A
Annie_wang 已提交
983
> **NOTE**
A
Annie_wang 已提交
984 985
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
986

987 988 989 990 991 992 993 994 995 996
**System API**: This is a system API.

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.DistributedCore

**Return value**

| Type                 | Description                  |
| ------------------- | -------------------- |
G
gloria 已提交
997
|  Promise\<Array\<[PeerInfo](#peerinfo8)>> | Promise used to return the online peer devices, in an array of **PeerInfo** objects.|
998 999 1000 1001 1002

**Example**

```js
async function example() {
A
Annie_wang 已提交
1003 1004 1005 1006 1007 1008 1009 1010 1011
  media.getActivePeers().then((devicesInfo) => {
    if (devicesInfo != undefined) {
      console.info('get distributed info ' + JSON.stringify(devicesInfo));
    } else {
      console.info('get distributed info is undefined!');
    }
  }).catch((error) => {
    console.error('get distributed info failed with error: ' + error);
  });
1012 1013 1014 1015 1016 1017 1018 1019 1020
}
```

### getActivePeers<sup>8+</sup>

getActivePeers(callback: AsyncCallback\<Array\<PeerInfo>>): void;

Obtains information about online peer devices. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
1021
> **NOTE**
A
Annie_wang 已提交
1022 1023
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
1024

1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
**System API**: This is a system API.

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.DistributedCore

**Return value**

| Type                 | Description                  |
| ------------------- | -------------------- |
A
Annie_wang 已提交
1035
| callback: AsyncCallback\<Array\<[PeerInfo](#peerinfo8)>> | Callback invoked to return the online peer devices, in an array of **PeerInfo** objects.|
1036 1037 1038 1039 1040

**Example**

```js
async function example() {
A
Annie_wang 已提交
1041 1042 1043 1044 1045 1046 1047
  media.getActivePeers((error, devicesInfo) => {
    if (devicesInfo != undefined) {
      console.info('get distributed info ' + JSON.stringify(devicesInfo));
    } else {
      console.error('get distributed failed with error: ' + error);
    }
  });
1048 1049 1050 1051 1052 1053 1054 1055 1056
}
```

### getAllPeers<sup>8+</sup>

getAllPeers(): Promise\<Array\<PeerInfo>>;

Obtains information about all peer devices. This API uses a promise to return the result.

A
Annie_wang 已提交
1057
> **NOTE**
A
Annie_wang 已提交
1058 1059
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
1060

1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
**System API**: This is a system API.

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.DistributedCore

**Return value**

| Type                 | Description                  |
| ------------------- | -------------------- |
G
gloria 已提交
1071
|  Promise\<Array\<[PeerInfo](#peerinfo8)>> | Promise used to return all peer devices, in an array of **PeerInfo** objects.|
1072 1073 1074 1075 1076

**Example**

```js
async function example() {
A
Annie_wang 已提交
1077 1078 1079 1080 1081 1082 1083 1084 1085
  media.getAllPeers().then((devicesInfo) => {
    if (devicesInfo != undefined) {
      console.info('get distributed info ' + JSON.stringify(devicesInfo));
    } else {
      console.info('get distributed info is undefined!');
    }
  }).catch((error) => {
    console.error('get distributed info failed with error: ' + error);
  });
1086 1087 1088 1089 1090 1091 1092
}
```

### getAllPeers<sup>8+</sup>

getAllPeers(callback: AsyncCallback\<Array\<PeerInfo>>): void;

A
Annie_wang 已提交
1093
Obtains information about all peer devices. This API uses an asynchronous callback to return the result.
1094

A
Annie_wang 已提交
1095
> **NOTE**
A
Annie_wang 已提交
1096 1097
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
1098

1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
**System API**: This is a system API.

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.DistributedCore

**Return value**

| Type                 | Description                  |
| ------------------- | -------------------- |
A
Annie_wang 已提交
1109
| callback: AsyncCallback\<Array\<[PeerInfo](#peerinfo8)>> | Callback invoked to return all peer devices, in an array of **PeerInfo** objects.|
1110 1111 1112 1113 1114

**Example**

```js
async function example() {
A
Annie_wang 已提交
1115 1116 1117 1118 1119 1120 1121
  media.getAllPeers((error, devicesInfo) => {
    if (devicesInfo != undefined) {
      console.info('get distributed info ' + JSON.stringify(devicesInfo));
    } else {
      console.error('get distributed failed with error: ' + error);
    }
  });
1122 1123
}
```
W
wusongqing 已提交
1124

W
wusongqing 已提交
1125
## FileAsset<sup>7+</sup>
W
wusongqing 已提交
1126 1127 1128

Provides APIs for encapsulating file asset attributes.

G
gloria 已提交
1129
> **NOTE**
A
Annie_wang 已提交
1130
>
A
Annie_wang 已提交
1131 1132
> - The system attempts to parse the file content if the file is an audio or video file. The actual field values will be restored from the passed values during scanning on some devices.
> - Some devices may not support the modification of **orientation**. You are advised to use [ModifyImageProperty](js-apis-image.md#modifyimageproperty9) of the **image** module.
A
Annie_wang 已提交
1133
> - This API is deprecated since API version 9. Use [PhotoAsset](js-apis-photoAccessHelper.md#photoasset) instead.
G
gloria 已提交
1134

W
wusongqing 已提交
1135 1136 1137 1138
### Attributes

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

W
wusongqing 已提交
1139
| Name                     | Type                    | Readable| Writable| Description                                                  |
W
wusongqing 已提交
1140
| ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ |
W
wusongqing 已提交
1141
| id                        | number                   | Yes  | No  | File asset ID.                                          |
L
lvyuanyuan 已提交
1142
| uri                       | string                   | Yes  | No  | File asset URI, for example, **file://media/image/2**.        |
W
wusongqing 已提交
1143 1144
| mimeType                  | string                   | Yes  | No  | Extended file attributes.                                          |
| mediaType<sup>8+</sup>    | [MediaType](#mediatype8) | Yes  | No  | Media type.                                              |
A
Annie_wang 已提交
1145 1146 1147 1148
| displayName               | string                   | Yes  | Yes  | File name, including the file name extension, to display.                                |
| title                     | string                   | Yes  | Yes  | Title in the file.                                              |
| relativePath<sup>8+</sup> | string                   | Yes  | Yes  | Relative path of the user directory.                                      |
| parent<sup>8+</sup>       | number                   | Yes  | No  | Parent directory ID. Since SDK of API version 10, an asset can exist in multiple albums. Therefore, this attribute is incompatible. The obtained value is always **0**.                       |
W
wusongqing 已提交
1149
| size                      | number                   | Yes  | No  | File size, in bytes.                                |
G
Gloria 已提交
1150 1151 1152
| dateAdded                 | number                   | Yes  | No  | Date when the file was added. The value is the number of seconds elapsed since the Epoch time.        |
| dateModified              | number                   | Yes  | No  | Date when the file content (not the file name) was last modified. The value is the number of seconds elapsed since the Epoch time.|
| dateTaken                 | number                   | Yes  | No  | Date when the file (photo) was taken. The value is the number of seconds elapsed since the Epoch time.        |
W
wusongqing 已提交
1153 1154 1155 1156 1157
| artist<sup>8+</sup>       | string                   | Yes  | No  | Artist of the file.                                                  |
| audioAlbum<sup>8+</sup>   | string                   | Yes  | No  | Audio album.                                                  |
| width                     | number                   | Yes  | No  | Image width, in pixels.                                |
| height                    | number                   | Yes  | No  | Image height, in pixels.                                |
| orientation               | number                   | Yes  | Yes  | Image display direction (clockwise rotation angle, for example, 0, 90, or 180, in degrees).|
W
wusongqing 已提交
1158
| duration<sup>8+</sup>     | number                   | Yes  | No  | Duration, in ms.                                  |
A
Annie_wang 已提交
1159 1160 1161
| albumId                   | number                   | Yes  | No  | ID of the album to which the file belongs. Since SDK of API version 10, an asset can exist in multiple albums. Therefore, this attribute is incompatible. The obtained value is always **0**.                  |
| albumUri<sup>8+</sup>     | string                   | Yes  | No  | URI of the album to which the file belongs. Since SDK of API version 10, an asset can exist in multiple albums. Therefore, this attribute is incompatible. The obtained value is always an empty string.                     |
| albumName                 | string                   | Yes  | No  | Name of the album to which the file belongs. Since SDK of API version 10, an asset can exist in multiple albums. Therefore, this attribute is incompatible. The obtained value is always an empty string.                    |
W
wusongqing 已提交
1162 1163 1164 1165 1166 1167 1168

### isDirectory<sup>8+</sup>

isDirectory(callback: AsyncCallback&lt;boolean&gt;): void

Checks whether this file asset is a directory. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
1169
> **NOTE**
A
Annie_wang 已提交
1170 1171
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
1172

W
wusongqing 已提交
1173 1174 1175 1176 1177 1178
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1179
| Name     | Type                          | Mandatory  | Description                 |
W
wusongqing 已提交
1180
| -------- | ---------------------------- | ---- | ------------------- |
A
Annie_wang 已提交
1181
| callback | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result. The value **true** means the file asset is a directory; the value false means the opposite.|
W
wusongqing 已提交
1182 1183 1184

**Example**

1185
```js
W
wusongqing 已提交
1186
async function example() {
A
Annie_wang 已提交
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.isDirectory((error, isDirectory) => {
    if (error) {
      console.error('isDirectory failed with error: ' + error);
    } else {
      console.info('isDirectory result:' + isDirectory);
    }
  });
  fetchFileResult.close();
W
wusongqing 已提交
1204 1205 1206 1207 1208 1209 1210 1211 1212
}
```

### isDirectory<sup>8+</sup>

isDirectory():Promise&lt;boolean&gt;

Checks whether this file asset is a directory. This API uses a promise to return the result.

A
Annie_wang 已提交
1213
> **NOTE**
A
Annie_wang 已提交
1214 1215
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
1216

W
wusongqing 已提交
1217 1218 1219 1220 1221 1222
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
1223 1224
| Type                    | Description                          |
| ---------------------- | ---------------------------- |
A
Annie_wang 已提交
1225
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the file asset is a directory; the value **false** means the opposite.|
W
wusongqing 已提交
1226 1227 1228

**Example**

1229
```js
W
wusongqing 已提交
1230
async function example() {
A
Annie_wang 已提交
1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.isDirectory().then((isDirectory) => {
    console.info('isDirectory result:' + isDirectory);
  }).catch((error) => {
    console.error('isDirectory failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1246 1247 1248 1249 1250 1251 1252
}
```

### commitModify<sup>8+</sup>

commitModify(callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
1253 1254 1255
Commits the modification on the file metadata to the database. This API uses an asynchronous callback to return the result.

> **NOTE**
A
Annie_wang 已提交
1256
>
A
Annie_wang 已提交
1257
> - This API is deprecated since API version 9. Use [commitModify](js-apis-photoAccessHelper.md#commitmodify) instead.
A
Annie_wang 已提交
1258
> - Since the SDK of API version 10, **audio** does not have the **orientation** attribute. Therefore, the **orientation** attribute of the audio resource cannot be modified by **commitModify()**. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
W
wusongqing 已提交
1259 1260 1261 1262 1263 1264 1265

**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1266 1267
| Name     | Type                       | Mandatory  | Description   |
| -------- | ------------------------- | ---- | ----- |
A
Annie_wang 已提交
1268
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.|
W
wusongqing 已提交
1269 1270 1271

**Example**

1272
```js
W
wusongqing 已提交
1273
async function example() {
A
Annie_wang 已提交
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.title = 'newtitle';
  asset.commitModify(() => {
    console.info('commitModify successfully');
  });
  fetchFileResult.close();
W
wusongqing 已提交
1288 1289 1290 1291 1292 1293 1294
}
```

### commitModify<sup>8+</sup>

commitModify(): Promise&lt;void&gt;

A
Annie_wang 已提交
1295 1296 1297
Commits the modification on the file asset to the database. This API uses a promise to return the result.

> **NOTE**
A
Annie_wang 已提交
1298
>
A
Annie_wang 已提交
1299
> - This API is deprecated since API version 9. Use [commitModify](js-apis-photoAccessHelper.md#commitmodify-1) instead.
A
Annie_wang 已提交
1300
> Since the SDK of API version 10, **audio** does not have the **orientation** attribute. Therefore, the **orientation** attribute of the audio resource cannot be modified by **commitModify()**. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
W
wusongqing 已提交
1301 1302 1303 1304 1305 1306 1307

**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
1308 1309
| Type                 | Description        |
| ------------------- | ---------- |
A
Annie_wang 已提交
1310
| Promise&lt;void&gt; | Promise that returns no value.|
W
wusongqing 已提交
1311 1312 1313

**Example**

1314
```js
W
wusongqing 已提交
1315
async function example() {
A
Annie_wang 已提交
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.title = 'newtitle';
  await asset.commitModify();
  fetchFileResult.close();
W
wusongqing 已提交
1328 1329 1330 1331 1332 1333 1334 1335 1336
}
```

### open<sup>8+</sup>

open(mode: string, callback: AsyncCallback&lt;number&gt;): void

Opens this file asset. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
1337
> **NOTE**
A
Annie_wang 已提交
1338 1339 1340 1341 1342
>
> - This API is deprecated since API version 9. Use [open](js-apis-photoAccessHelper.md#open) instead.
>
> - If a file is opened in 'w' mode, the returned file descriptor (FD) cannot be used to read the file. 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 close the file.
W
wusongqing 已提交
1343

W
wusongqing 已提交
1344
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
W
wusongqing 已提交
1345 1346 1347 1348 1349

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1350 1351
| Name     | Type                         | Mandatory  | Description                                 |
| -------- | --------------------------- | ---- | ----------------------------------- |
A
Annie_wang 已提交
1352 1353
| mode     | string                      | Yes   | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).|
| callback | AsyncCallback&lt;number&gt; | Yes   | Callback invoked to return the FD of the file opened.                           |
W
wusongqing 已提交
1354 1355 1356

**Example**

1357
```js
W
wusongqing 已提交
1358
async function example() {
A
Annie_wang 已提交
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
  let mediaType = mediaLibrary.MediaType.IMAGE;
  let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
  const path = await media.getPublicDirectory(DIR_IMAGE);
  const asset = await media.createAsset(mediaType, 'image00003.jpg', path);
  asset.open('rw', (error, fd) => {
    if (fd > 0) {
      asset.close(fd);
    } else {
      console.error('File Open failed with error: ' + error);
    }
  });
W
wusongqing 已提交
1370 1371 1372 1373 1374 1375 1376 1377 1378
}
```

### open<sup>8+</sup>

open(mode: string): Promise&lt;number&gt;

Opens this file asset. This API uses a promise to return the result.

A
Annie_wang 已提交
1379
> **NOTE**
A
Annie_wang 已提交
1380 1381 1382 1383
>
> - This API is deprecated since API version 9. Use [open](js-apis-photoAccessHelper.md#open-1) instead.
> - If a file is opened in 'w' mode, the returned FD cannot be used to read the file. 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 close the file.
W
wusongqing 已提交
1384

W
wusongqing 已提交
1385
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
W
wusongqing 已提交
1386 1387 1388 1389 1390

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1391 1392
| Name | Type    | Mandatory  | Description                                 |
| ---- | ------ | ---- | ----------------------------------- |
A
Annie_wang 已提交
1393
| mode | string | Yes   | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).|
W
wusongqing 已提交
1394 1395 1396

**Return value**

W
wusongqing 已提交
1397 1398
| Type                   | Description           |
| --------------------- | ------------- |
A
Annie_wang 已提交
1399
| Promise&lt;number&gt; | Promise used to return the FD of the file opened.|
W
wusongqing 已提交
1400 1401 1402

**Example**

1403
```js
W
wusongqing 已提交
1404
async function example() {
A
Annie_wang 已提交
1405 1406 1407 1408 1409 1410 1411 1412 1413
  let mediaType = mediaLibrary.MediaType.IMAGE;
  let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
  const path = await media.getPublicDirectory(DIR_IMAGE);
  const asset = await media.createAsset(mediaType, 'image00003.jpg', path);
  asset.open('rw').then((fd) => {
    console.info('File open fd: ' + fd);
  }).catch((error) => {
    console.error('File open failed with error: ' + error);
  });
W
wusongqing 已提交
1414 1415 1416 1417 1418 1419 1420
}
```

### close<sup>8+</sup>

close(fd: number, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
1421
Closes a file. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1422

A
Annie_wang 已提交
1423
> **NOTE**
A
Annie_wang 已提交
1424 1425
>
> This API is deprecated since API version 9. Use [close](js-apis-photoAccessHelper.md#close) instead.
A
Annie_wang 已提交
1426

W
wusongqing 已提交
1427
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
W
wusongqing 已提交
1428 1429 1430 1431 1432

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1433 1434
| Name     | Type                       | Mandatory  | Description   |
| -------- | ------------------------- | ---- | ----- |
A
Annie_wang 已提交
1435 1436
| fd       | number                    | Yes   | FD of the file to close.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.|
W
wusongqing 已提交
1437 1438 1439

**Example**

1440
```js
W
wusongqing 已提交
1441
async function example() {
A
Annie_wang 已提交
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.open('rw').then((fd) => {
    console.info('File open fd: ' + fd);
    asset.close(fd, (error) => {
      if (error) {
        console.error('asset.close failed with error: ' + error);
      } else {
        console.info('asset.close successfully');
      }
W
wusongqing 已提交
1459
    });
A
Annie_wang 已提交
1460 1461 1462 1463
  }).catch((error) => {
    console.error('File open failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1464 1465 1466 1467 1468 1469 1470
}
```

### close<sup>8+</sup>

close(fd: number): Promise&lt;void&gt;

A
Annie_wang 已提交
1471
Closes a file. This API uses a promise to return the result.
W
wusongqing 已提交
1472

A
Annie_wang 已提交
1473
> **NOTE**
A
Annie_wang 已提交
1474 1475
>
> This API is deprecated since API version 9. Use [close](js-apis-photoAccessHelper.md#close-1) instead.
A
Annie_wang 已提交
1476

W
wusongqing 已提交
1477
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
W
wusongqing 已提交
1478 1479 1480 1481 1482

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1483 1484
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
A
Annie_wang 已提交
1485
| fd   | number | Yes   | FD of the file to close.|
W
wusongqing 已提交
1486 1487 1488

**Return value**

W
wusongqing 已提交
1489 1490
| Type                 | Description        |
| ------------------- | ---------- |
A
Annie_wang 已提交
1491
| Promise&lt;void&gt; | Promise that returns no value.|
W
wusongqing 已提交
1492 1493 1494

**Example**

1495
```js
W
wusongqing 已提交
1496
async function example() {
A
Annie_wang 已提交
1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.open('rw').then((fd) => {
    console.info('File fd!' + fd);
    asset.close(fd).then(() => {
      console.info('asset.close successfully');
    }).catch((closeErr) => {
      console.error('asset.close fail, closeErr: ' + closeErr);
W
wusongqing 已提交
1512
    });
A
Annie_wang 已提交
1513 1514 1515 1516
  }).catch((error) => {
    console.error('open File failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1517 1518 1519 1520 1521 1522 1523 1524 1525
}
```

### getThumbnail<sup>8+</sup>

getThumbnail(callback: AsyncCallback&lt;image.PixelMap&gt;): void

Obtains the thumbnail of this file asset. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
1526
> **NOTE**
A
Annie_wang 已提交
1527 1528
>
> This API is deprecated since API version 9. Use [close](js-apis-photoAccessHelper.md#getThumbnail) instead.
A
Annie_wang 已提交
1529

W
wusongqing 已提交
1530 1531 1532 1533 1534 1535
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1536 1537
| Name     | Type                                 | Mandatory  | Description              |
| -------- | ----------------------------------- | ---- | ---------------- |
A
Annie_wang 已提交
1538
| callback | AsyncCallback&lt;image.PixelMap&gt; | Yes   | Callback invoked to return the PixelMap of the thumbnail.|
W
wusongqing 已提交
1539 1540 1541

**Example**

1542
```js
W
wusongqing 已提交
1543
async function example() {
A
Annie_wang 已提交
1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.getThumbnail((error, pixelmap) => {
    if (error) {
      console.error('mediaLibrary getThumbnail failed with error: ' + error);
    } else {
      console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
    }
  });
  fetchFileResult.close();
W
wusongqing 已提交
1561 1562 1563 1564 1565 1566 1567
}
```

### getThumbnail<sup>8+</sup>

getThumbnail(size: Size, callback: AsyncCallback&lt;image.PixelMap&gt;): void

A
Annie_wang 已提交
1568
Obtains the file thumbnail of the given size. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1569

A
Annie_wang 已提交
1570
> **NOTE**
A
Annie_wang 已提交
1571 1572
>
> This API is deprecated since API version 9. Use [close](js-apis-photoAccessHelper.md#getThumbnail-1) instead.
A
Annie_wang 已提交
1573

W
wusongqing 已提交
1574 1575 1576 1577 1578 1579
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1580 1581 1582
| Name     | Type                                 | Mandatory  | Description              |
| -------- | ----------------------------------- | ---- | ---------------- |
| size     | [Size](#size8)                      | Yes   | Size of the thumbnail.           |
A
Annie_wang 已提交
1583
| callback | AsyncCallback&lt;image.PixelMap&gt; | Yes   | Callback invoked to return the PixelMap of the thumbnail.|
W
wusongqing 已提交
1584 1585 1586

**Example**

1587
```js
W
wusongqing 已提交
1588
async function example() {
A
Annie_wang 已提交
1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let size = { width: 720, height: 720 };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.getThumbnail(size, (error, pixelmap) => {
    if (error) {
      console.error('mediaLibrary getThumbnail failed with error: ' + error);
    } else {
      console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
    }
  });
  fetchFileResult.close();
W
wusongqing 已提交
1607 1608 1609 1610 1611 1612 1613
}
```

### getThumbnail<sup>8+</sup>

getThumbnail(size?: Size): Promise&lt;image.PixelMap&gt;

A
Annie_wang 已提交
1614
Obtains the file thumbnail of the given size. This API uses a promise to return the result.
W
wusongqing 已提交
1615

A
Annie_wang 已提交
1616
> **NOTE**
A
Annie_wang 已提交
1617 1618
>
> This API is deprecated since API version 9. Use [close](js-apis-photoAccessHelper.md#getThumbnail-2) instead.
A
Annie_wang 已提交
1619

W
wusongqing 已提交
1620 1621 1622 1623 1624 1625
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1626 1627 1628
| Name | Type            | Mandatory  | Description   |
| ---- | -------------- | ---- | ----- |
| size | [Size](#size8) | No   | Size of the thumbnail.|
W
wusongqing 已提交
1629 1630 1631

**Return value**

W
wusongqing 已提交
1632 1633
| Type                           | Description                   |
| ----------------------------- | --------------------- |
A
Annie_wang 已提交
1634
| Promise&lt;image.PixelMap&gt; | Promise used to return the PixelMap of the thumbnail.|
W
wusongqing 已提交
1635 1636 1637

**Example**

1638
```js
W
wusongqing 已提交
1639
async function example() {
A
Annie_wang 已提交
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let size = { width: 720, height: 720 };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.getThumbnail(size).then((pixelmap) => {
    console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
  }).catch((error) => {
    console.error('mediaLibrary getThumbnail failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1656 1657 1658 1659 1660 1661 1662 1663 1664
}
```

### favorite<sup>8+</sup>

favorite(isFavorite: boolean, callback: AsyncCallback&lt;void&gt;): void

Favorites or unfavorites this file asset. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
1665
> **NOTE**
A
Annie_wang 已提交
1666 1667
>
> This API is deprecated since API version 9. Use [setFavorite](js-apis-photoAccessHelper.md#setfavorite) instead.
A
Annie_wang 已提交
1668

W
wusongqing 已提交
1669 1670 1671 1672 1673 1674
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1675 1676
| Name       | Type                       | Mandatory  | Description                                |
| ---------- | ------------------------- | ---- | ---------------------------------- |
A
Annie_wang 已提交
1677 1678
| isFavorite | boolean                   | Yes   | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.|
| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.                             |
W
wusongqing 已提交
1679 1680 1681

**Example**

1682
```js
W
wusongqing 已提交
1683
async function example() {
A
Annie_wang 已提交
1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.favorite(true,(error) => {
    if (error) {
      console.error('mediaLibrary favorite failed with error: ' + error);
    } else {
      console.info('mediaLibrary favorite Successful');
    }
  });
  fetchFileResult.close();
W
wusongqing 已提交
1701 1702 1703 1704 1705 1706 1707 1708 1709
}
```

### favorite<sup>8+</sup>

favorite(isFavorite: boolean): Promise&lt;void&gt;

Favorites or unfavorites this file asset. This API uses a promise to return the result.

A
Annie_wang 已提交
1710
> **NOTE**
A
Annie_wang 已提交
1711 1712
>
> This API is deprecated since API version 9. Use [setFavorite](js-apis-photoAccessHelper.md#setfavorite-1) instead.
A
Annie_wang 已提交
1713

W
wusongqing 已提交
1714 1715 1716 1717 1718 1719
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1720 1721
| Name       | Type     | Mandatory  | Description                                |
| ---------- | ------- | ---- | ---------------------------------- |
A
Annie_wang 已提交
1722
| isFavorite | boolean | Yes   | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.|
W
wusongqing 已提交
1723 1724 1725

**Return value**

W
wusongqing 已提交
1726 1727
| Type                 | Description        |
| ------------------- | ---------- |
A
Annie_wang 已提交
1728
| Promise&lt;void&gt; | Promise that returns no value.|
W
wusongqing 已提交
1729 1730 1731

**Example**

1732
```js
W
wusongqing 已提交
1733
async function example() {
A
Annie_wang 已提交
1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.favorite(true).then(() => {
    console.info('mediaLibrary favorite Successful');
  }).catch((error) => {
    console.error('mediaLibrary favorite failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1749 1750 1751 1752 1753 1754 1755 1756 1757
}
```

### isFavorite<sup>8+</sup>

isFavorite(callback: AsyncCallback&lt;boolean&gt;): void

Checks whether this file asset is favorited. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
1758
> **NOTE**
A
Annie_wang 已提交
1759 1760
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
1761

W
wusongqing 已提交
1762 1763 1764 1765 1766 1767
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1768 1769
| Name     | Type                          | Mandatory  | Description         |
| -------- | ---------------------------- | ---- | ----------- |
A
Annie_wang 已提交
1770
| callback | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result. The value **true** means the file asset is favorited; the value **false** means the opposite.|
W
wusongqing 已提交
1771 1772 1773

**Example**

1774
```js
W
wusongqing 已提交
1775
async function example() {
A
Annie_wang 已提交
1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.isFavorite((error, isFavorite) => {
    if (error) {
      console.error('mediaLibrary favoriisFavoritete failed with error: ' + error);
    } else {
      console.info('mediaLibrary isFavorite Successful, isFavorite result: ' + isFavorite);
    }
  });
  fetchFileResult.close();
W
wusongqing 已提交
1793 1794 1795 1796 1797 1798 1799 1800 1801
}
```

### isFavorite<sup>8+</sup>

isFavorite():Promise&lt;boolean&gt;

Checks whether this file asset is favorited. This API uses a promise to return the result.

A
Annie_wang 已提交
1802
> **NOTE**
A
Annie_wang 已提交
1803 1804
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
1805

W
wusongqing 已提交
1806 1807 1808 1809 1810 1811
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
1812 1813
| Type                    | Description                |
| ---------------------- | ------------------ |
A
Annie_wang 已提交
1814
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the file asset is favorited; the value **false** means the opposite.|
W
wusongqing 已提交
1815 1816 1817

**Example**

1818
```js
W
wusongqing 已提交
1819
async function example() {
A
Annie_wang 已提交
1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.isFavorite().then((isFavorite) => {
    console.info('mediaLibrary isFavorite Successful, isFavorite result: ' + isFavorite);
  }).catch((error) => {
    console.error('mediaLibrary favoriisFavoritete failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845
}
```

### trash<sup>8+</sup>

trash(isTrash: boolean, callback: AsyncCallback&lt;void&gt;): void

Moves this file asset to the trash. This API uses an asynchronous callback to return the result.

Files in the trash are not actually deleted. You can set **isTrash** to **false** to restore the files from the trash.

A
Annie_wang 已提交
1846
> **NOTE**
A
Annie_wang 已提交
1847 1848
>
> This API is deprecated since API version 9. Use [deleteAssets](js-apis-photoAccessHelper.md#deleteAssets) instead.
A
Annie_wang 已提交
1849

W
wusongqing 已提交
1850 1851 1852 1853 1854 1855
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1856 1857
| Name     | Type                       | Mandatory  | Description       |
| -------- | ------------------------- | ---- | --------- |
A
Annie_wang 已提交
1858 1859
| isTrash  | boolean                   | Yes   | Whether to move the file asset to the trash.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.    |
W
wusongqing 已提交
1860 1861 1862

**Example**

1863
```js
W
wusongqing 已提交
1864
async function example() {
A
Annie_wang 已提交
1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.trash(true, (error) => {
    if (error) {
      console.error('mediaLibrary trash failed with error: ' + error);
    } else {
      console.info('mediaLibrary trash Successful');
    }
  });
  fetchFileResult.close();
W
wusongqing 已提交
1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892
}
```

### trash<sup>8+</sup>

trash(isTrash: boolean): Promise&lt;void&gt;

Moves this file asset to the trash. This API uses a promise to return the result.

Files in the trash are not actually deleted. You can set **isTrash** to **false** to restore the files from the trash.

A
Annie_wang 已提交
1893
> **NOTE**
A
Annie_wang 已提交
1894 1895
>
> This API is deprecated since API version 9. Use [deleteAssets](js-apis-photoAccessHelper.md#deleteAssets-1) instead.
A
Annie_wang 已提交
1896

W
wusongqing 已提交
1897 1898 1899 1900 1901 1902
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1903 1904
| Name    | Type     | Mandatory  | Description       |
| ------- | ------- | ---- | --------- |
A
Annie_wang 已提交
1905
| isTrash | boolean | Yes   | Whether to move the file asset to the trash.|
W
wusongqing 已提交
1906 1907 1908

**Return value**

W
wusongqing 已提交
1909 1910
| Type                 | Description        |
| ------------------- | ---------- |
A
Annie_wang 已提交
1911
| Promise&lt;void&gt; | Promise that returns no value.|
W
wusongqing 已提交
1912 1913 1914

**Example**

1915
```js
W
wusongqing 已提交
1916
async function example() {
A
Annie_wang 已提交
1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.trash(true).then(() => {
    console.info('trash successfully');
  }).catch((error) => {
    console.error('trash failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1932 1933 1934 1935 1936 1937 1938 1939 1940
}
```

### isTrash<sup>8+</sup>

isTrash(callback: AsyncCallback&lt;boolean&gt;): void

Checks whether this file asset is in the trash. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
1941
> **NOTE**
A
Annie_wang 已提交
1942 1943
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
1944

W
wusongqing 已提交
1945 1946 1947 1948 1949 1950
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1951 1952
| Name     | Type                          | Mandatory  | Description             |
| -------- | ---------------------------- | ---- | --------------- |
A
Annie_wang 已提交
1953
| callback | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result. The value **true** means the file is in the trash; the value **false** means the opposite.|
W
wusongqing 已提交
1954 1955 1956

**Example**

1957
```js
W
wusongqing 已提交
1958
async function example() {
A
Annie_wang 已提交
1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.isTrash((error, isTrash) => {
    if (error) {
      console.error('Failed to get trash state failed with error: ' + error);
      return;
    }
    console.info('Get trash state successfully, isTrash result: ' + isTrash);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1976 1977 1978 1979 1980 1981 1982 1983 1984
}
```

### isTrash<sup>8+</sup>

isTrash():Promise&lt;boolean&gt;

Checks whether this file asset is in the trash. This API uses a promise to return the result.

A
Annie_wang 已提交
1985
> **NOTE**
A
Annie_wang 已提交
1986 1987
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
1988

W
wusongqing 已提交
1989 1990 1991 1992 1993 1994
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
1995 1996
| Type                 | Description                  |
| ------------------- | -------------------- |
A
Annie_wang 已提交
1997
| Promise&lt;void&gt; | Promise used to return the result. The value **true** means the file is in the trash; the value **false** means the opposite.|
W
wusongqing 已提交
1998 1999 2000

**Example**

2001
```js
W
wusongqing 已提交
2002
async function example() {
A
Annie_wang 已提交
2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.isTrash().then((isTrash) => {
    console.info('isTrash result: ' + isTrash);
  }).catch((error) => {
    console.error('isTrash failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
2018 2019 2020
}
```

W
wusongqing 已提交
2021
## FetchFileResult<sup>7+</sup>
W
wusongqing 已提交
2022

A
Annie_wang 已提交
2023
Provides APIs to manage the file retrieval result.
W
wusongqing 已提交
2024

A
Annie_wang 已提交
2025
> **NOTE**
A
Annie_wang 已提交
2026 2027
>
> This API is deprecated since API version 9. Use [FetchResult](js-apis-photoAccessHelper.md#fetchresult) instead.
A
Annie_wang 已提交
2028

W
wusongqing 已提交
2029
### getCount<sup>7+</sup>
W
wusongqing 已提交
2030 2031 2032 2033 2034

getCount(): number

Obtains the total number of files in the result set.

A
Annie_wang 已提交
2035
> **NOTE**
A
Annie_wang 已提交
2036 2037
>
> This API is deprecated since API version 9. Use [getCount](js-apis-photoAccessHelper.md#getcount) instead.
A
Annie_wang 已提交
2038

W
wusongqing 已提交
2039 2040 2041 2042
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
2043 2044
| Type    | Description      |
| ------ | -------- |
A
Annie_wang 已提交
2045
| number | Returns the total number of files obtained.|
W
wusongqing 已提交
2046 2047 2048

**Example**

2049
```js
W
wusongqing 已提交
2050
async function example() {
A
Annie_wang 已提交
2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061
  let fileKeyObj = mediaLibrary.FileKey;
  let fileType = mediaLibrary.MediaType.FILE;
  let getFileCountOneOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [fileType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getFileCountOneOp);
  const fetchCount = fetchFileResult.getCount();
  console.info('fetchCount result: ' + fetchCount);
  fetchFileResult.close();
W
wusongqing 已提交
2062 2063 2064
}
```

W
wusongqing 已提交
2065
### isAfterLast<sup>7+</sup>
W
wusongqing 已提交
2066 2067 2068 2069 2070

isAfterLast(): boolean

Checks whether the cursor is in the last row of the result set.

A
Annie_wang 已提交
2071
> **NOTE**
A
Annie_wang 已提交
2072 2073
>
> This API is deprecated since API version 9. Use [isAfterLast](js-apis-photoAccessHelper.md#isafterlast) instead.
A
Annie_wang 已提交
2074

W
wusongqing 已提交
2075 2076 2077 2078
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
2079 2080
| Type     | Description                                |
| ------- | ---------------------------------- |
A
Annie_wang 已提交
2081
| boolean | Returns **true** if the cursor is in the last row of the result set; returns **false** otherwise.|
W
wusongqing 已提交
2082 2083 2084

**Example**

2085
```js
W
wusongqing 已提交
2086
async function example() {
A
Annie_wang 已提交
2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  const fetchCount = fetchFileResult.getCount();
  console.info('mediaLibrary fetchFileResult.getCount, count:' + fetchCount);
  let fileAsset = await fetchFileResult.getFirstObject();
  for (var i = 1; i < fetchCount; i++) {
    fileAsset = await fetchFileResult.getNextObject();
    if(i == fetchCount - 1) {
      var result = fetchFileResult.isAfterLast();
      console.info('mediaLibrary fileAsset isAfterLast result: ' + result);
      fetchFileResult.close();
W
wusongqing 已提交
2104
    }
A
Annie_wang 已提交
2105
  }
W
wusongqing 已提交
2106 2107 2108
}
```

W
wusongqing 已提交
2109
### close<sup>7+</sup>
W
wusongqing 已提交
2110 2111 2112

close(): void

A
Annie_wang 已提交
2113
Releases and invalidates this **FetchFileResult** instance. After this instance is released, the APIs in this instance cannot be invoked.
W
wusongqing 已提交
2114

A
Annie_wang 已提交
2115
> **NOTE**
A
Annie_wang 已提交
2116 2117
>
> This API is deprecated since API version 9. Use [close](js-apis-photoAccessHelper.md#close) instead.
A
Annie_wang 已提交
2118

W
wusongqing 已提交
2119 2120 2121 2122
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Example**

2123
```js
W
wusongqing 已提交
2124
async function example() {
A
Annie_wang 已提交
2125 2126 2127 2128 2129 2130 2131 2132 2133
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.close();
W
wusongqing 已提交
2134 2135 2136
}
```

W
wusongqing 已提交
2137
### getFirstObject<sup>7+</sup>
W
wusongqing 已提交
2138 2139 2140 2141 2142

getFirstObject(callback: AsyncCallback&lt;FileAsset&gt;): void

Obtains the first file asset in the result set. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
2143
> **NOTE**
A
Annie_wang 已提交
2144 2145
>
> This API is deprecated since API version 9. Use [getFirstObject](js-apis-photoAccessHelper.md#getfirstobject) instead.
A
Annie_wang 已提交
2146

W
wusongqing 已提交
2147 2148 2149 2150
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2151 2152
| Name  | Type                                         | Mandatory| Description                                       |
| -------- | --------------------------------------------- | ---- | ------------------------------------------- |
A
Annie_wang 已提交
2153
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes  | Callback invoked to return the first **FileAsset** object in the result set.|
W
wusongqing 已提交
2154 2155 2156

**Example**

2157
```js
W
wusongqing 已提交
2158
async function example() {
A
Annie_wang 已提交
2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getFirstObject((error, fileAsset) => {
    if (error) {
      console.error('fetchFileResult getFirstObject failed with error: ' + error);
      return;
    }
    console.info('getFirstObject successfully, displayName : ' + fileAsset.displayName);
    fetchFileResult.close();
  })
W
wusongqing 已提交
2175 2176 2177
}
```

W
wusongqing 已提交
2178
### getFirstObject<sup>7+</sup>
W
wusongqing 已提交
2179 2180 2181 2182 2183

getFirstObject(): Promise&lt;FileAsset&gt;

Obtains the first file asset in the result set. This API uses a promise to return the result.

A
Annie_wang 已提交
2184
> **NOTE**
A
Annie_wang 已提交
2185 2186
>
> This API is deprecated since API version 9. Use [getFirstObject](js-apis-photoAccessHelper.md#getfirstobject-1) instead.
A
Annie_wang 已提交
2187

W
wusongqing 已提交
2188 2189 2190 2191
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
2192 2193
| Type                                   | Description                      |
| --------------------------------------- | -------------------------- |
A
Annie_wang 已提交
2194
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the first **FileAsset** object in the result set.|
W
wusongqing 已提交
2195 2196 2197

**Example**

2198
```js
W
wusongqing 已提交
2199
async function example() {
A
Annie_wang 已提交
2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getFirstObject().then((fileAsset) => {
    console.info('getFirstObject successfully, displayName: ' + fileAsset.displayName);
    fetchFileResult.close();
  }).catch((error) => {
    console.error('getFirstObject failed with error: ' + error);
  });
W
wusongqing 已提交
2214 2215 2216
}
```

W
wusongqing 已提交
2217
### getNextObject<sup>7+</sup>
W
wusongqing 已提交
2218

2219
getNextObject(callback: AsyncCallback&lt;FileAsset&gt;): void
W
wusongqing 已提交
2220 2221

Obtains the next file asset in the result set. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
2222

A
Annie_wang 已提交
2223 2224 2225
> **NOTE**
>
> - Before using this API, you must use [getFirstObject](#getfirstobject7) to obtain the first file asset and then use [isAfterLast](#isafterlast7) to check that the cursor does not point to the last file asset in the result set.
A
Annie_wang 已提交
2226
> - This API is deprecated since API version 9. Use [getNextObject](js-apis-photoAccessHelper.md#getnextobject) instead.
W
wusongqing 已提交
2227 2228 2229 2230 2231

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2232 2233
| Name   | Type                                         | Mandatory| Description                                     |
| --------- | --------------------------------------------- | ---- | ----------------------------------------- |
A
Annie_wang 已提交
2234
| callbacke | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes  | Callback invoked to return the next **FileAsset** object in the result set.|
W
wusongqing 已提交
2235 2236 2237

**Example**

2238
```js
W
wusongqing 已提交
2239
async function example() {
A
Annie_wang 已提交
2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  let fileAsset = await fetchFileResult.getFirstObject();
  console.log('fetchFileResult getFirstObject successfully, displayName: ' + fileAsset.displayName);
  if (!fetchFileResult.isAfterLast()) {
    fetchFileResult.getNextObject((error, fileAsset) => {
      if (error) {
        console.error('fetchFileResult getNextObject failed with error: ' + error);
        return;
      }
      console.log('fetchFileResult getNextObject successfully, displayName: ' + fileAsset.displayName);
      fetchFileResult.close();
    })
  }
W
wusongqing 已提交
2260
}
G
Gloria 已提交
2261

W
wusongqing 已提交
2262 2263
```

W
wusongqing 已提交
2264
### getNextObject<sup>7+</sup>
W
wusongqing 已提交
2265

2266
getNextObject(): Promise&lt;FileAsset&gt;
W
wusongqing 已提交
2267 2268

Obtains the next file asset in the result set. This API uses a promise to return the result.
A
Annie_wang 已提交
2269

A
Annie_wang 已提交
2270 2271 2272
> **NOTE**
>
> - Before using this API, you must use [getFirstObject](#getfirstobject7) to obtain the first file asset and then use [isAfterLast](#isafterlast7) to check that the cursor does not point to the last file asset in the result set.
A
Annie_wang 已提交
2273
> - This API is deprecated since API version 9. Use [getNextObject](js-apis-photoAccessHelper.md#getnextobject-1) instead.
W
wusongqing 已提交
2274 2275 2276 2277 2278

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
2279 2280
| Type                                   | Description             |
| --------------------------------------- | ----------------- |
A
Annie_wang 已提交
2281
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the next **FileAsset** object in the result set.|
W
wusongqing 已提交
2282 2283 2284

**Example**

2285
```js
W
wusongqing 已提交
2286
async function example() {
A
Annie_wang 已提交
2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  let fileAsset = await fetchFileResult.getFirstObject();
  console.log('fetchFileResult getFirstObject successfully, displayName: ' + fileAsset.displayName);
  if (!fetchFileResult.isAfterLast()) {
    fetchFileResult.getNextObject().then((fileAsset) => {
      console.info('fetchFileResult getNextObject successfully, displayName: ' + fileAsset.displayName);
      fetchFileResult.close();
    }).catch((error) => {
      console.error('fetchFileResult getNextObject failed with error: ' + error);
    })
  }
W
wusongqing 已提交
2305 2306 2307
}
```

W
wusongqing 已提交
2308
### getLastObject<sup>7+</sup>
W
wusongqing 已提交
2309 2310 2311 2312 2313

getLastObject(callback: AsyncCallback&lt;FileAsset&gt;): void

Obtains the last file asset in the result set. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
2314
> **NOTE**
A
Annie_wang 已提交
2315 2316
>
> This API is deprecated since API version 9. Use [getLastObject](js-apis-photoAccessHelper.md#getlastobject) instead.
A
Annie_wang 已提交
2317

W
wusongqing 已提交
2318 2319 2320 2321
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2322 2323
| Name  | Type                                         | Mandatory| Description                       |
| -------- | --------------------------------------------- | ---- | --------------------------- |
A
Annie_wang 已提交
2324
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes  | Callback invoked to return the last **FileAsset** object in the result set.|
W
wusongqing 已提交
2325 2326 2327

**Example**

2328
```js
W
wusongqing 已提交
2329
async function example() {
A
Annie_wang 已提交
2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getLastObject((error, fileAsset) => {
    if (error) {
      console.error('getLastObject failed with error: ' + error);
      return;
    }
    console.info('getLastObject successfully, displayName: ' + fileAsset.displayName);
    fetchFileResult.close();
  })
W
wusongqing 已提交
2346 2347 2348
}
```

W
wusongqing 已提交
2349
### getLastObject<sup>7+</sup>
W
wusongqing 已提交
2350 2351 2352 2353 2354

getLastObject(): Promise&lt;FileAsset&gt;

Obtains the last file asset in the result set. This API uses a promise to return the result.

A
Annie_wang 已提交
2355
> **NOTE**
A
Annie_wang 已提交
2356 2357
>
> This API is deprecated since API version 9. Use [getLastObject](js-apis-photoAccessHelper.md#getlastobject-1) instead.
A
Annie_wang 已提交
2358

W
wusongqing 已提交
2359 2360 2361 2362
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
2363 2364
| Type                                   | Description             |
| --------------------------------------- | ----------------- |
A
Annie_wang 已提交
2365
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the last **FileAsset** object in the result set.|
W
wusongqing 已提交
2366 2367 2368

**Example**

2369
```js
W
wusongqing 已提交
2370
async function example() {
A
Annie_wang 已提交
2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getLastObject().then((fileAsset) => {
    console.info('getLastObject successfully, displayName: ' + fileAsset.displayName);
    fetchFileResult.close();
  }).catch((error) => {
    console.error('getLastObject failed with error: ' + error);
  });
W
wusongqing 已提交
2385 2386 2387
}
```

W
wusongqing 已提交
2388
### getPositionObject<sup>7+</sup>
W
wusongqing 已提交
2389 2390 2391 2392 2393

getPositionObject(index: number, callback: AsyncCallback&lt;FileAsset&gt;): void

Obtains a file asset with the specified index in the result set. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
2394
> **NOTE**
A
Annie_wang 已提交
2395 2396
>
> This API is deprecated since API version 9. Use [getObjectByPosition](js-apis-photoAccessHelper.md#getobjectbyposition) instead.
A
Annie_wang 已提交
2397

W
wusongqing 已提交
2398 2399 2400 2401
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2402 2403
| Name      | Type                                      | Mandatory  | Description                |
| -------- | ---------------------------------------- | ---- | ------------------ |
G
Gloria 已提交
2404
| 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.    |
A
Annie_wang 已提交
2405
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes   | Callback invoked to return the **FileAsset** object with the specified index obtained.|
W
wusongqing 已提交
2406 2407 2408

**Example**

2409
```js
W
wusongqing 已提交
2410
async function example() {
A
Annie_wang 已提交
2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getPositionObject(0, (error, fileAsset) => {
    if (error) {
      console.error('getPositionObject failed with error: ' + error);
      return;
    }
    console.info('getPositionObject successfully, displayName: ' + fileAsset.displayName);
    fetchFileResult.close();
  })
W
wusongqing 已提交
2427 2428 2429
}
```

W
wusongqing 已提交
2430
### getPositionObject<sup>7+</sup>
W
wusongqing 已提交
2431 2432 2433 2434 2435

getPositionObject(index: number): Promise&lt;FileAsset&gt;

Obtains a file asset with the specified index in the result set. This API uses a promise to return the result.

A
Annie_wang 已提交
2436
> **NOTE**
A
Annie_wang 已提交
2437 2438
>
> This API is deprecated since API version 9. Use [getObjectByPosition](js-apis-photoAccessHelper.md#getobjectbyposition-1) instead.
A
Annie_wang 已提交
2439

W
wusongqing 已提交
2440 2441 2442 2443
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2444 2445
| Name   | Type    | Mandatory  | Description            |
| ----- | ------ | ---- | -------------- |
G
Gloria 已提交
2446
| 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.|
W
wusongqing 已提交
2447 2448 2449

**Return value**

W
wusongqing 已提交
2450 2451
| Type                                   | Description             |
| --------------------------------------- | ----------------- |
A
Annie_wang 已提交
2452
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the **FileAsset** object with the specified index obtained.|
W
wusongqing 已提交
2453 2454 2455

**Example**

2456
```js
W
wusongqing 已提交
2457
async function example() {
A
Annie_wang 已提交
2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getPositionObject(0).then((fileAsset) => {
    console.info('getPositionObject successfully, displayName: ' + fileAsset.displayName);
    fetchFileResult.close();
  }).catch((error) => {
    console.error('getPositionObject failed with error: ' + error);
  });
W
wusongqing 已提交
2472 2473 2474
}
```

W
wusongqing 已提交
2475
### getAllObject<sup>7+</sup>
W
wusongqing 已提交
2476 2477 2478 2479 2480

getAllObject(callback: AsyncCallback&lt;Array&lt;FileAsset&gt;&gt;): void

Obtains all the file assets in the result set. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
2481
> **NOTE**
A
Annie_wang 已提交
2482 2483
>
> This API is deprecated since API version 9. Use [getAllObjects](js-apis-photoAccessHelper.md#getallobjects) instead.
A
Annie_wang 已提交
2484

W
wusongqing 已提交
2485 2486 2487 2488
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2489 2490
| Name      | Type                                      | Mandatory  | Description                  |
| -------- | ---------------------------------------- | ---- | -------------------- |
A
Annie_wang 已提交
2491
| callback | AsyncCallback&lt;Array&lt;[FileAsset](#fileasset7)&gt;&gt; | Yes   | Callback invoked to return all the **FileAsset** objects in the result reset.|
W
wusongqing 已提交
2492 2493 2494

**Example**

2495
```js
W
wusongqing 已提交
2496
async function example() {
A
Annie_wang 已提交
2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getAllObject((error, fileAssetList) => {
    if (error) {
      console.error('getAllObject failed with error: ' + error);
      return;
    }
    for (let i = 0; i < fetchFileResult.getCount(); i++) {
      console.info('getAllObject fileAssetList ' + i + ' displayName: ' + fileAssetList[i].displayName);
    }
    fetchFileResult.close();
  })
W
wusongqing 已提交
2515 2516 2517
}
```

W
wusongqing 已提交
2518
### getAllObject<sup>7+</sup>
W
wusongqing 已提交
2519 2520 2521 2522 2523

getAllObject(): Promise&lt;Array&lt;FileAsset&gt;&gt;

Obtains all the file assets in the result set. This API uses a promise to return the result.

A
Annie_wang 已提交
2524
> **NOTE**
A
Annie_wang 已提交
2525 2526
>
> This API is deprecated since API version 9. Use [getAllObjects](js-apis-photoAccessHelper.md#getallobjects-1) instead.
A
Annie_wang 已提交
2527

W
wusongqing 已提交
2528 2529 2530 2531
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
2532 2533
| Type                                    | Description                 |
| ---------------------------------------- | --------------------- |
A
Annie_wang 已提交
2534
| Promise&lt;Array&lt;[FileAsset](#fileasset7)&gt;&gt; | Promise used to return all the **FileAsset** objects in the result reset.|
W
wusongqing 已提交
2535 2536 2537

**Example**

2538
```js
W
wusongqing 已提交
2539
async function example() {
A
Annie_wang 已提交
2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getAllObject().then((fileAssetList) => {
    for (let i = 0; i < fetchFileResult.getCount(); i++) {
      console.info('getAllObject fileAssetList ' + i + ' displayName: ' + fileAssetList[i].displayName);
    } 
    fetchFileResult.close();
  }).catch((error) => {
    console.error('getAllObject failed with error: ' + error);
  });
W
wusongqing 已提交
2556 2557 2558
}
```

W
wusongqing 已提交
2559
## Album<sup>7+</sup>
W
wusongqing 已提交
2560

A
Annie_wang 已提交
2561
Provides APIs to manage albums.
W
wusongqing 已提交
2562

A
Annie_wang 已提交
2563
> **NOTE**
A
Annie_wang 已提交
2564 2565
>
> This API is deprecated since API version 9. Use [Album](js-apis-photoAccessHelper.md#album) instead.
A
Annie_wang 已提交
2566

W
wusongqing 已提交
2567
### Attributes
W
wusongqing 已提交
2568 2569 2570

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

W
wusongqing 已提交
2571 2572
| Name          | Type   | Readable  | Writable  | Description     |
| ------------ | ------ | ---- | ---- | ------- |
W
wusongqing 已提交
2573
| albumId | number | Yes   | No   | Album ID.   |
A
Annie_wang 已提交
2574 2575 2576
| albumName | string | Yes   | Yes   | Name of the album.   |
| albumUri<sup>8+</sup> | string | Yes   | No   | URI of the album.  |
| dateModified | number | Yes   | No   | Date when the album was last modified.   |
W
wusongqing 已提交
2577 2578 2579
| count<sup>8+</sup> | number | Yes   | No   | Number of files in the album.|
| relativePath<sup>8+</sup> | string | Yes   | No   | Relative path of the album.   |
| coverUri<sup>8+</sup> | string | Yes   | No   | URI of the cover file of the album.|
W
wusongqing 已提交
2580 2581 2582 2583 2584

### commitModify<sup>8+</sup>

commitModify(callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
2585
Commits the modification on the album attributes to the database.
W
wusongqing 已提交
2586

A
Annie_wang 已提交
2587
> **NOTE**
A
Annie_wang 已提交
2588 2589
>
> This API is deprecated since API version 9. Use [commitModify](js-apis-photoAccessHelper.md#commitmodify-2) instead.
A
Annie_wang 已提交
2590

W
wusongqing 已提交
2591 2592 2593 2594 2595 2596
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2597 2598
| Name  | Type                     | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
A
Annie_wang 已提交
2599
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback that returns no value.|
W
wusongqing 已提交
2600 2601 2602

**Example**

2603
```js
W
wusongqing 已提交
2604
async function example() {
2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618
  // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'.
  let AlbumNoArgsfetchOp = {
    selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
    selectionArgs:['New Album 1'],
  };
  const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
  const album = albumList[0];
  album.albumName = 'hello';
  album.commitModify((error) => {
    if (error) {
      console.error('commitModify failed with error: ' + error);
      return;
    }
    console.info('commitModify successful.');
A
Annie_wang 已提交
2619
  });
W
wusongqing 已提交
2620 2621 2622 2623 2624 2625 2626
}
```

### commitModify<sup>8+</sup>

commitModify(): Promise&lt;void&gt;

A
Annie_wang 已提交
2627
Commits the modification on the album attributes to the database.
W
wusongqing 已提交
2628

A
Annie_wang 已提交
2629
> **NOTE**
A
Annie_wang 已提交
2630 2631
>
> This API is deprecated since API version 9. Use [commitModify](js-apis-photoAccessHelper.md#commitmodify-3) instead.
A
Annie_wang 已提交
2632

W
wusongqing 已提交
2633 2634 2635 2636 2637 2638
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
2639 2640
| Type                 | Description          |
| ------------------- | ------------ |
A
Annie_wang 已提交
2641
| Promise&lt;void&gt; | Promise that returns no value.|
W
wusongqing 已提交
2642 2643 2644

**Example**

2645
```js
W
wusongqing 已提交
2646
async function example() {
2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668
  // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'.
  let AlbumNoArgsfetchOp = {
    selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
    selectionArgs:['New Album 1'],
  };
  const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
  const album = albumList[0];
  album.albumName = 'hello';
  album.commitModify().then(() => {
    console.info('commitModify successfully');
  }).catch((error) => {
    console.error('commitModify failed with error: ' + error);
  });
}
```

### getFileAssets<sup>7+</sup>

getFileAssets(callback: AsyncCallback&lt;FetchFileResult&gt;): void

Obtains the file assets in this album. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
2669
> **NOTE**
A
Annie_wang 已提交
2670 2671
>
> This API is deprecated since API version 9. Use [getAssets](js-apis-photoAccessHelper.md#getassets) instead.
A
Annie_wang 已提交
2672

2673 2674 2675 2676 2677 2678 2679 2680
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

| Name  | Type                                               | Mandatory| Description                               |
| -------- | --------------------------------------------------- | ---- | ----------------------------------- |
A
Annie_wang 已提交
2681
| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | Yes  | Callback invoked to return the file retrieval result set of the album.|
2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704

**Example**

```js
async function example() {
  // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'.
  let AlbumNoArgsfetchOp = {
    selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
    selectionArgs:['New Album 1'],
  };
  // Obtain the albums that meet the retrieval options and return the album list.
  const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
  const album = albumList[0];
  // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album.
  album.getFileAssets((error, fetchFileResult) => {
    if (error) {
      console.error('album getFileAssets failed with error: ' + error);
      return;
    }
    let count = fetchFileResult.getCount();
    console.info('album getFileAssets successfully, count: ' + count);
    fetchFileResult.close();
  });
W
wusongqing 已提交
2705 2706 2707
}
```

W
wusongqing 已提交
2708
### getFileAssets<sup>7+</sup>
W
wusongqing 已提交
2709 2710 2711

getFileAssets(options: MediaFetchOptions, callback: AsyncCallback&lt;FetchFileResult&gt;): void

A
Annie_wang 已提交
2712 2713 2714
Obtains the file assets in this album based on specified conditions. This API uses an asynchronous callback to return the result.

> **NOTE**
A
Annie_wang 已提交
2715 2716
>
> This API is deprecated since API version 9. Use [getAssets](js-apis-photoAccessHelper.md#getassets) instead.
W
wusongqing 已提交
2717 2718 2719 2720 2721 2722 2723

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2724 2725 2726
| Name  | Type                                               | Mandatory| Description                               |
| -------- | --------------------------------------------------- | ---- | ----------------------------------- |
| options  | [MediaFetchOptions](#mediafetchoptions7)            | Yes  | Options for fetching the files.                     |
A
Annie_wang 已提交
2727
| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | Yes  | Callback invoked to return the file retrieval result set of the album.|
W
wusongqing 已提交
2728 2729 2730

**Example**

2731
```js
W
wusongqing 已提交
2732
async function example() {
2733 2734 2735 2736 2737 2738 2739 2740
  // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'.
  let AlbumNoArgsfetchOp = {
    selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
    selectionArgs:['New Album 1'],
  };
  let fileNoArgsfetchOp = {
    selections: '',
    selectionArgs: [],
A
Annie_wang 已提交
2741
  };
2742 2743 2744 2745 2746 2747 2748 2749
  // Obtain the albums that meet the retrieval options and return the album list.
  const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
  const album = albumList[0];
  // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album.
  album.getFileAssets(fileNoArgsfetchOp, (error, fetchFileResult) => {
    if (error) {
      console.error('album getFileAssets failed with error: ' + error);
      return;
W
wusongqing 已提交
2750
    }
2751 2752 2753 2754
    let count = fetchFileResult.getCount();
    console.info('album getFileAssets successfully, count: ' + count);
    fetchFileResult.close();
  });
W
wusongqing 已提交
2755 2756 2757
}
```

W
wusongqing 已提交
2758
### getFileAssets<sup>7+</sup>
W
wusongqing 已提交
2759 2760 2761

 getFileAssets(options?: MediaFetchOptions): Promise&lt;FetchFileResult&gt;

A
Annie_wang 已提交
2762 2763 2764
Obtains the file assets in this album based on specified conditions. This API uses a promise to return the result.

> **NOTE**
A
Annie_wang 已提交
2765 2766
>
> This API is deprecated since API version 9. Use [getAssets](js-apis-photoAccessHelper.md#getassets-1) instead.
W
wusongqing 已提交
2767 2768 2769 2770 2771 2772 2773

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2774 2775 2776
| Name | Type                                    | Mandatory| Description          |
| ------- | ---------------------------------------- | ---- | -------------- |
| options | [MediaFetchOptions](#mediafetchoptions7) | No  | Options for fetching the files.|
W
wusongqing 已提交
2777 2778 2779

**Return value**

W
wusongqing 已提交
2780 2781
| Type                                         | Description                     |
| --------------------------------------------- | ------------------------- |
A
Annie_wang 已提交
2782
| Promise<[FetchFileResult](#fetchfileresult7)> | Promise used to return the file retrieval result set of the album.|
W
wusongqing 已提交
2783 2784 2785

**Example**

2786
```js
W
wusongqing 已提交
2787
async function example() {
2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807
  // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'.
  let AlbumNoArgsfetchOp = {
    selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
    selectionArgs:['New Album 1'],
  };
  let fileNoArgsfetchOp = {
    selections: '',
    selectionArgs: [],
  };
  // Obtain the albums that meet the retrieval options and return the album list.
  const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
  const album = albumList[0];
  // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album.
  album.getFileAssets(fileNoArgsfetchOp).then((fetchFileResult) => {
    let count = fetchFileResult.getCount();
    console.info('album getFileAssets successfully, count: ' + count);
    fetchFileResult.close();
  }).catch((error) => {
    console.error('album getFileAssets failed with error: ' + error);
  });
W
wusongqing 已提交
2808 2809 2810 2811 2812
}
```

## PeerInfo<sup>8+</sup>

A
Annie_wang 已提交
2813
Defines information about a registered device.
2814

A
Annie_wang 已提交
2815
> **NOTE**
A
Annie_wang 已提交
2816 2817
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
2818

2819
**System API**: This is a system API.
W
wusongqing 已提交
2820

W
wusongqing 已提交
2821
**System capability**: SystemCapability.Multimedia.MediaLibrary.DistributedCore
W
wusongqing 已提交
2822

W
wusongqing 已提交
2823 2824 2825 2826 2827 2828
| Name      | Type                      | Readable| Writable| Description            |
| ---------- | -------------------------- | ---- | ---- | ---------------- |
| deviceName | string                     | Yes  | No  | Name of the registered device.  |
| networkId  | string                     | Yes  | No  | Network ID of the registered device.|
| deviceType | [DeviceType](#devicetype8) | Yes  | No  | Type of the registered device.        |
| isOnline   | boolean                    | Yes  | No  | Whether the registered device is online.        |
W
wusongqing 已提交
2829

W
wusongqing 已提交
2830
## MediaType<sup>8+</sup>
W
wusongqing 已提交
2831 2832 2833

Enumerates media types.

A
Annie_wang 已提交
2834
> **NOTE**
A
Annie_wang 已提交
2835 2836
>
> This API is deprecated since API version 9. Use [PhotoType](js-apis-photoAccessHelper.md#phototype) instead.
A
Annie_wang 已提交
2837

W
wusongqing 已提交
2838 2839
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

2840 2841 2842 2843 2844 2845
| Name |  Value|  Description|
| ----- |  ---- | ---- |
| FILE  |  0 | File.|
| IMAGE |  1 | Image.|
| VIDEO |  2 | Video.|
| AUDIO |  3 | Audio.|
W
wusongqing 已提交
2846

W
wusongqing 已提交
2847
## FileKey<sup>8+</sup>
W
wusongqing 已提交
2848 2849 2850

Enumerates key file information.

G
gloria 已提交
2851
> **NOTE**
A
Annie_wang 已提交
2852 2853
>
> - The **bucket_id** field may change after file rename or movement. Therefore, you must obtain the field again before using it.
A
Annie_wang 已提交
2854
> - This API is deprecated since API version 9. Use [PhotoKeys](js-apis-photoAccessHelper.md#photokeys) instead.
G
gloria 已提交
2855

W
wusongqing 已提交
2856 2857
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

2858
| Name         | Value             | Description                                                      |
W
wusongqing 已提交
2859
| ------------- | ------------------- | ---------------------------------------------------------- |
G
Gloria 已提交
2860
| ID            | 'file_id'             | File ID.                                                  |
A
Annie_wang 已提交
2861 2862
| RELATIVE_PATH | 'relative_path'       | Relative path of the user directory.                                          |
| DISPLAY_NAME  | 'display_name'        | File name displayed.                                                  |
G
Gloria 已提交
2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878
| PARENT        | 'parent'              | Parent directory ID.                                                  |
| MIME_TYPE     | 'mime_type'           | Extended file attributes, such as image/, video/, and file/*.                                            |
| MEDIA_TYPE    | 'media_type'          | Media type.                                                  |
| SIZE          | 'size'                | File size, in bytes.                                    |
| DATE_ADDED    | 'date_added'          | Date when the file was added. The value is the number of seconds elapsed since the Epoch time.            |
| DATE_MODIFIED | 'date_modified'       | Date when the file content (not the file name) was last modified. The value is the number of seconds elapsed since the Epoch time.|
| DATE_TAKEN    | 'date_taken'          | Date when the file (photo) was taken. The value is the number of seconds elapsed since the Epoch time.            |
| TITLE         | 'title'               | Title in the file.                                                  |
| ARTIST        | 'artist'              | Artist of the file.                                                      |
| AUDIOALBUM    | 'audio_album'         | Audio album.                                                      |
| DURATION      | 'duration'            | Duration, in ms.                                      |
| WIDTH         | 'width'               | Image width, in pixels.                                    |
| HEIGHT        | 'height'              | Image height, in pixels.                                    |
| ORIENTATION   | 'orientation'         | Image display direction (clockwise rotation angle, for example, 0, 90, and 180, in degrees).|
| ALBUM_ID      | 'bucket_id'           | ID of the album to which the file belongs.                                      |
| ALBUM_NAME    | 'bucket_display_name' | Name of the album to which the file belongs.                                        |
W
wusongqing 已提交
2879

W
wusongqing 已提交
2880
## DirectoryType<sup>8+</sup>
W
wusongqing 已提交
2881 2882 2883

Enumerates directory types.

A
Annie_wang 已提交
2884
> **NOTE**
A
Annie_wang 已提交
2885 2886
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
2887

W
wusongqing 已提交
2888 2889
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

2890 2891 2892 2893 2894 2895 2896 2897
| Name         | Value|  Description              |
| ------------- | --- | ------------------ |
| DIR_CAMERA    |  0 | Directory of camera files.|
| DIR_VIDEO     |  1 |  Directory of video files.      |
| DIR_IMAGE     |  2 | Directory of image files.      |
| DIR_AUDIO     |  3 | Directory of audio files.      |
| DIR_DOCUMENTS |  4 | Directory of documents.      |
| DIR_DOWNLOAD  |  5 |  Download directory.      |
W
wusongqing 已提交
2898

W
wusongqing 已提交
2899
## DeviceType<sup>8+</sup>
W
wusongqing 已提交
2900

A
Annie_wang 已提交
2901
Enumerates the device types.
2902

A
Annie_wang 已提交
2903
> **NOTE**
A
Annie_wang 已提交
2904 2905
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
2906

2907
**System API**: This is a system API.
W
wusongqing 已提交
2908

W
wusongqing 已提交
2909
**System capability**: SystemCapability.Multimedia.MediaLibrary.DistributedCore
W
wusongqing 已提交
2910

2911 2912 2913 2914 2915 2916 2917 2918 2919
| Name        |  Value| Description      |
| ------------ | --- | ---------- |
| TYPE_UNKNOWN |  0 | Unknown.|
| TYPE_LAPTOP  |  1 | Laptop.|
| TYPE_PHONE   |  2 | Phone.      |
| TYPE_TABLET  |  3 | Tablet.  |
| TYPE_WATCH   |  4 | Smart watch.  |
| TYPE_CAR     |  5 | Vehicle-mounted device.  |
| TYPE_TV      |  6 | TV.  |
W
wusongqing 已提交
2920

W
wusongqing 已提交
2921
## MediaFetchOptions<sup>7+</sup>
W
wusongqing 已提交
2922

A
Annie_wang 已提交
2923
Defines the options for fetching media files.
W
wusongqing 已提交
2924

A
Annie_wang 已提交
2925
> **NOTE**
A
Annie_wang 已提交
2926 2927
>
> This API is deprecated since API version 9. Use [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) instead.
A
Annie_wang 已提交
2928

W
wusongqing 已提交
2929 2930
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

2931 2932
| Name                   | Type               | Readable| Writable| Description                                                        |
| ----------------------- | ------------------- | ---- | ---- | ------------------------------------------------------------ |
A
Annie_wang 已提交
2933
| selections              | string              | Yes  | Yes  | Conditions for fetching files. The enumerated values in [FileKey](#filekey8) are used as the column names when files are fetched. <br/>Example:<br>selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ? OR ' + mediaLibrary.FileKey.MEDIA_TYPE + '= ?', |
A
Annie_wang 已提交
2934
| selectionArgs           | Array&lt;string&gt; | Yes  | Yes  | Values of the conditions specified in **selections**.<br>Example:<br>selectionArgs: [mediaLibrary.MediaType.IMAGE.toString(), mediaLibrary.MediaType.VIDEO.toString()], |
A
Annie_wang 已提交
2935
| 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. <br/>Example:<br>Ascending: order: mediaLibrary.FileKey.DATE_ADDED + ' ASC'<br>Descending: order: mediaLibrary.FileKey.DATE_ADDED + ' DESC' |
A
Annie_wang 已提交
2936
| uri<sup>8+</sup>        | string              | Yes  | Yes  | URI of the file.                                                     |
2937 2938
| 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.                        |
W
wusongqing 已提交
2939 2940 2941

## Size<sup>8+</sup>

A
Annie_wang 已提交
2942
Defines the image size.
2943

A
Annie_wang 已提交
2944
> **NOTE**
A
Annie_wang 已提交
2945 2946
>
> This API is deprecated since API version 9. Use [image.Size](js-apis-image.md#size) instead.
A
Annie_wang 已提交
2947

W
wusongqing 已提交
2948
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
W
wusongqing 已提交
2949

W
wusongqing 已提交
2950 2951 2952 2953
| Name    | Type    | Readable  | Writable  | Description      |
| ------ | ------ | ---- | ---- | -------- |
| width  | number | Yes   | Yes   | Image width, in pixels.|
| height | number | Yes   | Yes   | Image height, in pixels.|
W
wusongqing 已提交
2954

G
Gloria 已提交
2955
## MediaAssetOption
W
wusongqing 已提交
2956

A
Annie_wang 已提交
2957
Defines the media asset option.
W
wusongqing 已提交
2958

A
Annie_wang 已提交
2959
> **NOTE**
A
Annie_wang 已提交
2960 2961
>
> This API is deprecated since API version 9. There is no substitute API.
A
Annie_wang 已提交
2962

W
wusongqing 已提交
2963 2964
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

2965 2966 2967
| Name        | Type  | Readable| Writable| Description                                                        |
| ------------ | ------ | ---- | ---- | ------------------------------------------------------------ |
| src          | string | Yes  | Yes  | Application sandbox oath of the local file.                                      |
A
Annie_wang 已提交
2968 2969
| mimeType     | string | Yes  | Yes  | Multipurpose Internet Mail Extensions (MIME) type of the media.<br>The value can be 'image/\*', 'video/\*', 'audio/\*' or 'file/*'. |
| relativePath | string | Yes  | Yes  | Customized path of media assets, for example, **Pictures/**. If this parameter is unspecified, the default paths of media assets are as follows:<br> Default path of images: **'Pictures/'**<br> Default path of videos: **'Videos/'**<br> Default path of audio files: **'Audios/'**<br> Default path of documents: **'Documents/'** |
W
wusongqing 已提交
2970

G
Gloria 已提交
2971
## MediaSelectOption
W
wusongqing 已提交
2972

A
Annie_wang 已提交
2973 2974 2975
Defines the media selection option.

> **NOTE**
A
Annie_wang 已提交
2976 2977
>
> This API is deprecated since API version 9. There is no substitute API.
W
wusongqing 已提交
2978 2979 2980

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

2981 2982
| Name   | Type    | Readable| Writable| Description                  |
| ----- | ------ | ---- | ---- | -------------------- |
G
gloria 已提交
2983
| type  | 'image' &#124; 'video' &#124; 'media' | Yes   | Yes | Media type, which can be **image**, **media**, or **video**. Currently, only **media** is supported.|
A
Annie_wang 已提交
2984
| count | number | Yes   | Yes | Maximum number of media assets that can be selected.<br/>The value **1** means to select only one media asset; the value greater than **1** means to select multiple media assets. |