1e41f4b71Sopenharmony_ci# Managing System Albums 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **photoAccessHelper** module provides APIs for managing system albums, including **Favorites**, **Videos**, and **Screenshots**. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> - Before you get started, obtain a **PhotoAccessHelper** instance and apply for required permissions. For details, see [Before You Start](photoAccessHelper-preparation.md). 8e41f4b71Sopenharmony_ci> - Unless otherwise specified, the **PhotoAccessHelper** instance obtained in the **Before You Start** section is used to call **photoAccessHelper** APIs. If the code for obtaining the **PhotoAccessHelper** instance is missing, an error will be reported to indicate that **photoAccessHelper** is not defined. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ciTo ensure application running efficiency, most **PhotoAccessHelper** APIs are asynchronously implemented in callback or promise mode. The following examples use promise-based APIs. For details about the APIs, see [Album Management](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md). 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciUnless otherwise specified, all the media assets to be obtained in this document exist in the database. If no media asset is obtained when the sample code is executed, check whether the media assets exist in the database. 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci## Favorites 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci**Favorites** is a system album. Favoriting an image or video adds the image or video to **Favorites**; unfavoriting an image or video removes the image or video from **Favorites**. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci### Obtaining a Favorites Object 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ciUse [PhotoAccessHelper.getAlbums](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getalbums-2) to obtain a **Favorites** object. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci**Prerequisites** 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained. 25e41f4b71Sopenharmony_ci- The application has the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Requesting Permissions](photoAccessHelper-preparation.md#requesting-permissions). 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**How to Develop** 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci1. Set the album type to **photoAccessHelper.AlbumType.SYSTEM** and the album subtype to **photoAccessHelper.AlbumSubtype.FAVORITE**. 30e41f4b71Sopenharmony_ci2. Call **PhotoAccessHelper.getAlbums** to obtain a **Favorites** object. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci```ts 33e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper'; 34e41f4b71Sopenharmony_ciconst context = getContext(this); 35e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ciasync function example() { 38e41f4b71Sopenharmony_ci try { 39e41f4b71Sopenharmony_ci let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE); 40e41f4b71Sopenharmony_ci let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 41e41f4b71Sopenharmony_ci console.info('get favorite album successfully, albumUri: ' + album.albumUri); 42e41f4b71Sopenharmony_ci fetchResult.close(); 43e41f4b71Sopenharmony_ci } catch (err) { 44e41f4b71Sopenharmony_ci console.error('get favorite album failed with err: ' + err); 45e41f4b71Sopenharmony_ci } 46e41f4b71Sopenharmony_ci} 47e41f4b71Sopenharmony_ci``` 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci<!--Del--> 50e41f4b71Sopenharmony_ci### Favoriting an Image or Video (for System Applications Only) 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ciUse [MediaAssetChangeRequest.setFavorite](../../reference/apis-media-library-kit/js-apis-photoAccessHelper-sys.md#setfavorite11) and [PhotoAccessHelper.applyChanges](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#applychanges11) to add an image or video to **Favorites**. 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci**Prerequisites** 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained. 57e41f4b71Sopenharmony_ci- The application has the ohos.permission.READ_IMAGEVIDEO and ohos.permission.WRITE_IMAGEVIDEO permissions. For details, see [Requesting Permissions](photoAccessHelper-preparation.md#requesting-permissions). 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ciExample: Favorite an image. 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci**How to Develop** 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci1. [Obtain the image](photoAccessHelper-resource-guidelines.md#obtaining-media-assets). 64e41f4b71Sopenharmony_ci2. Call **MediaAssetChangeRequest.setFavorite** to set **favoriteState** to **true**. 65e41f4b71Sopenharmony_ci3. Call **PhotoAccessHelper.applyChanges** to apply the changes. 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci```ts 68e41f4b71Sopenharmony_ciimport dataSharePredicates from '@ohos.data.dataSharePredicates'; 69e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper'; 70e41f4b71Sopenharmony_ciconst context = getContext(this); 71e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ciasync function example() { 74e41f4b71Sopenharmony_ci let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 75e41f4b71Sopenharmony_ci predicates.equalTo(photoAccessHelper.PhotoKeys.DISPLAY_NAME, 'test.jpg'); 76e41f4b71Sopenharmony_ci let fetchOptions: photoAccessHelper.FetchOptions = { 77e41f4b71Sopenharmony_ci fetchColumns: [], 78e41f4b71Sopenharmony_ci predicates: predicates 79e41f4b71Sopenharmony_ci }; 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci try { 82e41f4b71Sopenharmony_ci let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 83e41f4b71Sopenharmony_ci let photoAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getFirstObject(); 84e41f4b71Sopenharmony_ci let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(photoAsset); 85e41f4b71Sopenharmony_ci let favoriteState = true; 86e41f4b71Sopenharmony_ci assetChangeRequest.setFavorite(favoriteState); 87e41f4b71Sopenharmony_ci await phAccessHelper.applyChanges(assetChangeRequest); 88e41f4b71Sopenharmony_ci } catch (err) { 89e41f4b71Sopenharmony_ci console.error('setFavorite failed with err: ' + err); 90e41f4b71Sopenharmony_ci } 91e41f4b71Sopenharmony_ci} 92e41f4b71Sopenharmony_ci``` 93e41f4b71Sopenharmony_ci<!--DelEnd--> 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci### Obtaining Images and Videos in Favorites 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci[Obtain a **Favorites** object](#obtaining-a-favorites-object), and call [Album.getAssets](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getassets-3) to obtain the assets in **Favorites**. 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci**Prerequisites** 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained. 102e41f4b71Sopenharmony_ci- The application has the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Requesting Permissions](photoAccessHelper-preparation.md#requesting-permissions). 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ciExample: Obtain an image from **Favorites**. 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci**How to Develop** 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci1. [Obtain a **Favorites** object](#obtaining-a-favorites-object). 109e41f4b71Sopenharmony_ci2. Set **fetchOptions** for obtaining the image. 110e41f4b71Sopenharmony_ci3. Call **Album.getAssets** to obtain the image assets. 111e41f4b71Sopenharmony_ci4. Call [FetchResult.getFirstObject](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getfirstobject-1) to obtain the first image from the result set. 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci```ts 114e41f4b71Sopenharmony_ciimport dataSharePredicates from '@ohos.data.dataSharePredicates'; 115e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper'; 116e41f4b71Sopenharmony_ciconst context = getContext(this); 117e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ciasync function example() { 120e41f4b71Sopenharmony_ci let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 121e41f4b71Sopenharmony_ci let fetchOptions: photoAccessHelper.FetchOptions = { 122e41f4b71Sopenharmony_ci fetchColumns: [], 123e41f4b71Sopenharmony_ci predicates: predicates 124e41f4b71Sopenharmony_ci }; 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci try { 127e41f4b71Sopenharmony_ci let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE); 128e41f4b71Sopenharmony_ci let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 129e41f4b71Sopenharmony_ci console.info('get favorite album successfully, albumUri: ' + album.albumUri); 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 132e41f4b71Sopenharmony_ci let photoAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getFirstObject(); 133e41f4b71Sopenharmony_ci console.info('favorite album getAssets successfully, photoAsset displayName: ' + photoAsset.displayName); 134e41f4b71Sopenharmony_ci photoFetchResult.close(); 135e41f4b71Sopenharmony_ci albumFetchResult.close(); 136e41f4b71Sopenharmony_ci } catch (err) { 137e41f4b71Sopenharmony_ci console.error('favorite failed with err: ' + err); 138e41f4b71Sopenharmony_ci } 139e41f4b71Sopenharmony_ci} 140e41f4b71Sopenharmony_ci``` 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci<!--Del--> 143e41f4b71Sopenharmony_ci### Unfavoriting an Image or Video (for System Applications Only) 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ciUse [MediaAssetChangeRequest.setFavorite](../../reference/apis-media-library-kit/js-apis-photoAccessHelper-sys.md#setfavorite11) and [PhotoAccessHelper.applyChanges](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#applychanges11) to remove an image or video from **Favorites**. 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci**Prerequisites** 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained. 150e41f4b71Sopenharmony_ci- The application has the ohos.permission.READ_IMAGEVIDEO and ohos.permission.WRITE_IMAGEVIDEO permissions. For details, see [Requesting Permissions](photoAccessHelper-preparation.md#requesting-permissions). 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ciExample: Unfavorite an image. 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci**How to Develop** 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci1. [Obtain the image in **Favorites**](#obtaining-images-and-videos-in-favorites). 157e41f4b71Sopenharmony_ci2. Call **MediaAssetChangeRequest.setFavorite** to set **favoriteState** to **false**. 158e41f4b71Sopenharmony_ci3. Call **PhotoAccessHelper.applyChanges** to apply the changes. 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci```ts 162e41f4b71Sopenharmony_ciimport dataSharePredicates from '@ohos.data.dataSharePredicates'; 163e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper'; 164e41f4b71Sopenharmony_ciconst context = getContext(this); 165e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ciasync function example() { 168e41f4b71Sopenharmony_ci let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 169e41f4b71Sopenharmony_ci let fetchOptions: photoAccessHelper.FetchOptions = { 170e41f4b71Sopenharmony_ci fetchColumns: [], 171e41f4b71Sopenharmony_ci predicates: predicates 172e41f4b71Sopenharmony_ci }; 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci try { 175e41f4b71Sopenharmony_ci let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE); 176e41f4b71Sopenharmony_ci let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 177e41f4b71Sopenharmony_ci console.info('get favorite album successfully, albumUri: ' + album.albumUri); 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 180e41f4b71Sopenharmony_ci let photoAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getFirstObject(); 181e41f4b71Sopenharmony_ci console.info('favorite album getAssets successfully, photoAsset displayName: ' + photoAsset.displayName); 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(photoAsset); 184e41f4b71Sopenharmony_ci let favoriteState = false; 185e41f4b71Sopenharmony_ci assetChangeRequest.setFavorite(favoriteState); 186e41f4b71Sopenharmony_ci await phAccessHelper.applyChanges(assetChangeRequest); 187e41f4b71Sopenharmony_ci photoFetchResult.close(); 188e41f4b71Sopenharmony_ci albumFetchResult.close(); 189e41f4b71Sopenharmony_ci } catch (err) { 190e41f4b71Sopenharmony_ci console.error('setFavorite failed with err: ' + err); 191e41f4b71Sopenharmony_ci } 192e41f4b71Sopenharmony_ci} 193e41f4b71Sopenharmony_ci``` 194e41f4b71Sopenharmony_ci<!--DelEnd--> 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci## Videos 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci**Videos** is a system album that holds media assets of the video type in user files. 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci### Obtaining a Videos Object 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ciUse [PhotoAccessHelper.getAlbums](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getalbums-2) to obtain a **Videos** object. 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci**Prerequisites** 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained. 207e41f4b71Sopenharmony_ci- The application has the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Requesting Permissions](photoAccessHelper-preparation.md#requesting-permissions). 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci**How to Develop** 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci1. Set the album type to **photoAccessHelper.AlbumType.SYSTEM** and the album subtype to **photoAccessHelper.AlbumSubtype.VIDEO**. 212e41f4b71Sopenharmony_ci2. Use **PhotoAccessHelper.getAlbums** to obtain a **Videos** object. 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci```ts 215e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper'; 216e41f4b71Sopenharmony_ciconst context = getContext(this); 217e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ciasync function example() { 220e41f4b71Sopenharmony_ci try { 221e41f4b71Sopenharmony_ci let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.VIDEO); 222e41f4b71Sopenharmony_ci let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 223e41f4b71Sopenharmony_ci console.info('get video album successfully, albumUri: ' + album.albumUri); 224e41f4b71Sopenharmony_ci fetchResult.close(); 225e41f4b71Sopenharmony_ci } catch (err) { 226e41f4b71Sopenharmony_ci console.error('get video album failed with err: ' + err); 227e41f4b71Sopenharmony_ci } 228e41f4b71Sopenharmony_ci} 229e41f4b71Sopenharmony_ci``` 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci### Obtaining a Video from Videos 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci[Obtain a **Videos** object](#obtaining-a-videos-object), and call [Album.getAssets](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getassets-3) to obtain video assets in the **Videos** album. 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci**Prerequisites** 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained. 238e41f4b71Sopenharmony_ci- The application has the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Requesting Permissions](photoAccessHelper-preparation.md#requesting-permissions). 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ciExample: Obtain a video in **Videos**. 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci**How to Develop** 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci1. [Obtain a **Videos** object](#obtaining-a-videos-object). 245e41f4b71Sopenharmony_ci2. Set **fetchOptions** for obtaining the video. 246e41f4b71Sopenharmony_ci3. Call **Album.getAssets** to obtain video assets. 247e41f4b71Sopenharmony_ci4. Call [FetchResult.getFirstObject](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getfirstobject-1) to obtain the first video. 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci```ts 250e41f4b71Sopenharmony_ciimport dataSharePredicates from '@ohos.data.dataSharePredicates'; 251e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper'; 252e41f4b71Sopenharmony_ciconst context = getContext(this); 253e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ciasync function example() { 256e41f4b71Sopenharmony_ci let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 257e41f4b71Sopenharmony_ci let fetchOptions: photoAccessHelper.FetchOptions = { 258e41f4b71Sopenharmony_ci fetchColumns: [], 259e41f4b71Sopenharmony_ci predicates: predicates 260e41f4b71Sopenharmony_ci }; 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci try { 263e41f4b71Sopenharmony_ci let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.VIDEO); 264e41f4b71Sopenharmony_ci let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 265e41f4b71Sopenharmony_ci console.info('get video album successfully, albumUri: ' + album.albumUri); 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci let videoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 268e41f4b71Sopenharmony_ci let photoAsset: photoAccessHelper.PhotoAsset = await videoFetchResult.getFirstObject(); 269e41f4b71Sopenharmony_ci console.info('video album getAssets successfully, photoAsset displayName: ' + photoAsset.displayName); 270e41f4b71Sopenharmony_ci videoFetchResult.close(); 271e41f4b71Sopenharmony_ci albumFetchResult.close(); 272e41f4b71Sopenharmony_ci } catch (err) { 273e41f4b71Sopenharmony_ci console.error('video failed with err: ' + err); 274e41f4b71Sopenharmony_ci } 275e41f4b71Sopenharmony_ci} 276e41f4b71Sopenharmony_ci``` 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci<!--Del--> 279e41f4b71Sopenharmony_ci## Screenshots (for System Applications Only) 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci**Screenshots** is a system album that holds user's screenshots and screen recording files. 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci### Obtaining a Screenshots Object 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ciUse [PhotoAccessHelper.getAlbums](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getalbums-2) to obtain a **Screenshots** object. 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_ci**Prerequisites** 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained. 290e41f4b71Sopenharmony_ci- The application has the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Requesting Permissions](photoAccessHelper-preparation.md#requesting-permissions). 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci**How to Develop** 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci1. Set the album type to **photoAccessHelper.AlbumType.SYSTEM** and the album subtype to **photoAccessHelper.AlbumSubtype.SCREENSHOT**. 295e41f4b71Sopenharmony_ci2. Use **PhotoAccessHelper.getAlbums** to obtain a **Screenshots** object. 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci```ts 298e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper'; 299e41f4b71Sopenharmony_ciconst context = getContext(this); 300e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ciasync function example() { 303e41f4b71Sopenharmony_ci try { 304e41f4b71Sopenharmony_ci let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.SCREENSHOT); 305e41f4b71Sopenharmony_ci let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 306e41f4b71Sopenharmony_ci console.info('get screenshot album successfully, albumUri: ' + album.albumUri); 307e41f4b71Sopenharmony_ci fetchResult.close(); 308e41f4b71Sopenharmony_ci } catch (err) { 309e41f4b71Sopenharmony_ci console.error('get screenshot album failed with err: ' + err); 310e41f4b71Sopenharmony_ci } 311e41f4b71Sopenharmony_ci} 312e41f4b71Sopenharmony_ci``` 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci### Obtaining Media Assets in Screenshots 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci[Obtain a **Screenshots** object](#obtaining-a-screenshots-object), and call [Album.getAssets](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getassets-3) to obtain the media assets in **Screenshots**. 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci**Prerequisites** 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained. 321e41f4b71Sopenharmony_ci- The application has the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Requesting Permissions](photoAccessHelper-preparation.md#requesting-permissions). 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_ciExample: Obtain a media asset from **Screenshots**. 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ci**How to Develop** 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci1. [Obtain a **Screenshots** object](#obtaining-a-screenshots-object). 328e41f4b71Sopenharmony_ci2. Set **fetchOptions** for obtaining the media asset. 329e41f4b71Sopenharmony_ci3. Call **Album.getAssets** to obtain media assets. 330e41f4b71Sopenharmony_ci4. Call [FetchResult.getFirstObject](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getfirstobject-1) to obtain the first media asset. 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci```ts 333e41f4b71Sopenharmony_ciimport dataSharePredicates from '@ohos.data.dataSharePredicates'; 334e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper'; 335e41f4b71Sopenharmony_ciconst context = getContext(this); 336e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ciasync function example() { 339e41f4b71Sopenharmony_ci let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 340e41f4b71Sopenharmony_ci let fetchOptions: photoAccessHelper.FetchOptions = { 341e41f4b71Sopenharmony_ci fetchColumns: [], 342e41f4b71Sopenharmony_ci predicates: predicates 343e41f4b71Sopenharmony_ci }; 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci try { 346e41f4b71Sopenharmony_ci let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.SCREENSHOT); 347e41f4b71Sopenharmony_ci let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 348e41f4b71Sopenharmony_ci console.info('get screenshot album successfully, albumUri: ' + album.albumUri); 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ci let screenshotFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 351e41f4b71Sopenharmony_ci let photoAsset: photoAccessHelper.PhotoAsset = await screenshotFetchResult.getFirstObject(); 352e41f4b71Sopenharmony_ci console.info('screenshot album getAssets successfully, photoAsset displayName: ' + photoAsset.displayName); 353e41f4b71Sopenharmony_ci screenshotFetchResult.close(); 354e41f4b71Sopenharmony_ci albumFetchResult.close(); 355e41f4b71Sopenharmony_ci } catch (err) { 356e41f4b71Sopenharmony_ci console.error('screenshot album failed with err: ' + err); 357e41f4b71Sopenharmony_ci } 358e41f4b71Sopenharmony_ci} 359e41f4b71Sopenharmony_ci``` 360e41f4b71Sopenharmony_ci<!--DelEnd--> 361