1e41f4b71Sopenharmony_ci# Managing User Albums
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **photoAccessHelper** module provides APIs for user album management, including creating or deleting a user album, adding images and videos to a user album, and deleting images and videos from a user album.
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_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.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci<!--Del-->
14e41f4b71Sopenharmony_ci## Creating a User Album (for System Applications Only)
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ciUse [MediaAlbumChangeRequest.createAlbumRequest](../../reference/apis-media-library-kit/js-apis-photoAccessHelper-sys.md#createalbumrequest11) and [PhotoAccessHelper.applyChanges](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#applychanges11) to create a user album.
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ciThe album name must meet the following requirements:
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci- The album name cannot exceed 255 characters.
21e41f4b71Sopenharmony_ci- The album name cannot contain any of the following characters:<br>. \ / : * ? " ' ` < > | { } [ ]
22e41f4b71Sopenharmony_ci- The album name is case-insensitive.
23e41f4b71Sopenharmony_ci- Duplicate album names are not allowed.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**Prerequisites**
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained.
28e41f4b71Sopenharmony_ci- The application has the ohos.permission.WRITE_IMAGEVIDEO permission. For details, see [Requesting Permissions](photoAccessHelper-preparation.md#requesting-permissions).
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ciExample: Create a user album.
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci**How to Develop**
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci1. Set the name of the album.
35e41f4b71Sopenharmony_ci2. Call **MediaAlbumChangeRequest.createAlbumRequest** to create an album change request object.
36e41f4b71Sopenharmony_ci3. Call **PhotoAccessHelper.applyChanges** to apply the changes.
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci```ts
39e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper';
40e41f4b71Sopenharmony_ciconst context = getContext(this);
41e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ciasync function example() {
44e41f4b71Sopenharmony_ci  try {
45e41f4b71Sopenharmony_ci    let albumName = 'albumName';
46e41f4b71Sopenharmony_ci    let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = photoAccessHelper.MediaAlbumChangeRequest.createAlbumRequest(context, albumName);
47e41f4b71Sopenharmony_ci    await phAccessHelper.applyChanges(albumChangeRequest);
48e41f4b71Sopenharmony_ci    let album: photoAccessHelper.Album = albumChangeRequest.getAlbum();
49e41f4b71Sopenharmony_ci    console.info('create album successfully, album name: ' + album.albumName + ' uri: ' + album.albumUri);
50e41f4b71Sopenharmony_ci  } catch (err) {
51e41f4b71Sopenharmony_ci    console.error('create album failed with err: ' + err);
52e41f4b71Sopenharmony_ci  }
53e41f4b71Sopenharmony_ci}
54e41f4b71Sopenharmony_ci```
55e41f4b71Sopenharmony_ci<!--DelEnd-->
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci## Obtaining a User Album
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ciUse [PhotoAccessHelper.getAlbums](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getalbums-2) to obtain user albums.
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci**Prerequisites**
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained.
64e41f4b71Sopenharmony_ci- The application has the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Requesting Permissions](photoAccessHelper-preparation.md#requesting-permissions).
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ciExample: Obtain the user album **albumName**.
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci**How to Develop**
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci1. Set **fetchOptions** for obtaining the user album.
71e41f4b71Sopenharmony_ci2. Call **PhotoAccessHelper.getAlbums** to obtain user albums.
72e41f4b71Sopenharmony_ci3. Call [FetchResult.getFirstObject](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getfirstobject-1) to obtain the first user album.
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci```ts
75e41f4b71Sopenharmony_ciimport dataSharePredicates from '@ohos.data.dataSharePredicates';
76e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper';
77e41f4b71Sopenharmony_ciconst context = getContext(this);
78e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ciasync function example() {
81e41f4b71Sopenharmony_ci  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
82e41f4b71Sopenharmony_ci  let albumName: photoAccessHelper.AlbumKeys = photoAccessHelper.AlbumKeys.ALBUM_NAME;
83e41f4b71Sopenharmony_ci  predicates.equalTo(albumName, 'albumName');
84e41f4b71Sopenharmony_ci  let fetchOptions: photoAccessHelper.FetchOptions = {
85e41f4b71Sopenharmony_ci    fetchColumns: [],
86e41f4b71Sopenharmony_ci    predicates: predicates
87e41f4b71Sopenharmony_ci  };
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci  try {
90e41f4b71Sopenharmony_ci    let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions);
91e41f4b71Sopenharmony_ci    let album: photoAccessHelper.Album = await fetchResult.getFirstObject();
92e41f4b71Sopenharmony_ci    console.info('getAlbums successfully, albumName: ' + album.albumName);
93e41f4b71Sopenharmony_ci    fetchResult.close();
94e41f4b71Sopenharmony_ci  } catch (err) {
95e41f4b71Sopenharmony_ci    console.error('getAlbums failed with err: ' + err);
96e41f4b71Sopenharmony_ci  }
97e41f4b71Sopenharmony_ci}
98e41f4b71Sopenharmony_ci```
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci## Renaming a User Album
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ciTo rename a user album, modify the **Album.albumName** attribute of the album.
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ciUse the [FetchResult](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#fetchresult) APIs to obtain the user album to rename, use [MediaAlbumChangeRequest.setAlbumName](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#setalbumname11) to rename the user album, and use [PhotoAccessHelper.applyChanges](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#applychanges11) to apply the changes to the database.
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ciThe new user album names must comply with the following requirements:
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci- The album name cannot exceed 255 characters.
109e41f4b71Sopenharmony_ci- The album name cannot contain any of the following characters:<br>. \ / : * ? " ' ` < > | { } [ ]
110e41f4b71Sopenharmony_ci- The album name is case-insensitive.
111e41f4b71Sopenharmony_ci- Duplicate album names are not allowed.
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci**Prerequisites**
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained.
116e41f4b71Sopenharmony_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).
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ciExample: Rename the user album **albumName**.
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci**How to Develop**
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci1. Set **fetchOptions** for obtaining the user album.
123e41f4b71Sopenharmony_ci2. Call **PhotoAccessHelper.getAlbums** to obtain user albums.
124e41f4b71Sopenharmony_ci3. Call [FetchResult.getFirstObject](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getfirstobject-1) to obtain the first user album.
125e41f4b71Sopenharmony_ci4. Call **MediaAlbumChangeRequest.setAlbumName** to set a new album name.
126e41f4b71Sopenharmony_ci5. Call **PhotoAccessHelper.applyChanges** to save the new album name to the database.
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci```ts
129e41f4b71Sopenharmony_ciimport dataSharePredicates from '@ohos.data.dataSharePredicates';
130e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper';
131e41f4b71Sopenharmony_ciconst context = getContext(this);
132e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ciasync function example() {
135e41f4b71Sopenharmony_ci  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
136e41f4b71Sopenharmony_ci  let albumName: photoAccessHelper.AlbumKeys = photoAccessHelper.AlbumKeys.ALBUM_NAME;
137e41f4b71Sopenharmony_ci  predicates.equalTo(albumName, 'albumName');
138e41f4b71Sopenharmony_ci  let fetchOptions: photoAccessHelper.FetchOptions = {
139e41f4b71Sopenharmony_ci    fetchColumns: [],
140e41f4b71Sopenharmony_ci    predicates: predicates
141e41f4b71Sopenharmony_ci  };
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci  try {
144e41f4b71Sopenharmony_ci    let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions);
145e41f4b71Sopenharmony_ci    let album: photoAccessHelper.Album = await fetchResult.getFirstObject();
146e41f4b71Sopenharmony_ci    console.info('getAlbums successfully, albumName: ' + album.albumName);
147e41f4b71Sopenharmony_ci    let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album);
148e41f4b71Sopenharmony_ci    let newAlbumName: string = 'newAlbumName';
149e41f4b71Sopenharmony_ci    albumChangeRequest.setAlbumName(newAlbumName);
150e41f4b71Sopenharmony_ci    await phAccessHelper.applyChanges(albumChangeRequest);
151e41f4b71Sopenharmony_ci    console.info('setAlbumName successfully, new albumName: ' + album.albumName);
152e41f4b71Sopenharmony_ci    fetchResult.close();
153e41f4b71Sopenharmony_ci  } catch (err) {
154e41f4b71Sopenharmony_ci    console.error('setAlbumName failed with err: ' + err);
155e41f4b71Sopenharmony_ci  }
156e41f4b71Sopenharmony_ci}
157e41f4b71Sopenharmony_ci```
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ci## Adding Images or Videos to a User Album
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci[Obtain the user album](#obtaining-a-user-album) and the images or videos to be added to the album, and then call [MediaAlbumChangeRequest.addAssets](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#addassets11) and [PhotoAccessHelper.applyChanges](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#applychanges11) to add the images or videos to the user album.
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci**Prerequisites**
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained.
166e41f4b71Sopenharmony_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).
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ciExample: Add an image to the user album **albumName**.
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci**How to Develop**
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci1. Set **albumFetchOptions** for obtaining the user album.
173e41f4b71Sopenharmony_ci2. Set **photoFetchOptions** for obtaining the image.
174e41f4b71Sopenharmony_ci3. Call **PhotoAccessHelper.getAlbums** to obtain user albums.
175e41f4b71Sopenharmony_ci4. Call [FetchResult.getFirstObject](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getfirstobject) to obtain the first user album.
176e41f4b71Sopenharmony_ci5. Call [PhotoAccessHelper.getAssets](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getassets) to obtain image assets.
177e41f4b71Sopenharmony_ci6. Call [FetchResult.getFirstObject](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getfirstobject) to obtain the first image from the result set.
178e41f4b71Sopenharmony_ci7. Call **MediaAlbumChangeRequest.addAssets** to add the image to the user album.
179e41f4b71Sopenharmony_ci8. Call **PhotoAccessHelper.applyChanges** to apply the changes.
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci```ts
182e41f4b71Sopenharmony_ciimport dataSharePredicates from '@ohos.data.dataSharePredicates';
183e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper';
184e41f4b71Sopenharmony_ciconst context = getContext(this);
185e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ciasync function example() {
188e41f4b71Sopenharmony_ci  let albumPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
189e41f4b71Sopenharmony_ci  let albumName: photoAccessHelper.AlbumKeys = photoAccessHelper.AlbumKeys.ALBUM_NAME;
190e41f4b71Sopenharmony_ci  albumPredicates.equalTo(albumName, 'albumName');
191e41f4b71Sopenharmony_ci  let albumFetchOptions: photoAccessHelper.FetchOptions = {
192e41f4b71Sopenharmony_ci    fetchColumns: [],
193e41f4b71Sopenharmony_ci    predicates: albumPredicates
194e41f4b71Sopenharmony_ci  };
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci  let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
197e41f4b71Sopenharmony_ci  let photoFetchOptions: photoAccessHelper.FetchOptions = {
198e41f4b71Sopenharmony_ci    fetchColumns: [],
199e41f4b71Sopenharmony_ci    predicates: photoPredicates
200e41f4b71Sopenharmony_ci  };
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci  try {
203e41f4b71Sopenharmony_ci    let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
204e41f4b71Sopenharmony_ci    let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
205e41f4b71Sopenharmony_ci    console.info('getAlbums successfully, albumName: ' + album.albumName);
206e41f4b71Sopenharmony_ci    let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(photoFetchOptions);
207e41f4b71Sopenharmony_ci    let photoAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getFirstObject();
208e41f4b71Sopenharmony_ci    console.info('getAssets successfully, albumName: ' + photoAsset.displayName);
209e41f4b71Sopenharmony_ci    let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album);
210e41f4b71Sopenharmony_ci    albumChangeRequest.addAssets([photoAsset]);
211e41f4b71Sopenharmony_ci    await phAccessHelper.applyChanges(albumChangeRequest);
212e41f4b71Sopenharmony_ci    console.info('succeed to add ' + photoAsset.displayName + ' to ' + album.albumName);
213e41f4b71Sopenharmony_ci    albumFetchResult.close();
214e41f4b71Sopenharmony_ci    photoFetchResult.close();
215e41f4b71Sopenharmony_ci  } catch (err) {
216e41f4b71Sopenharmony_ci    console.error('addAssets failed with err: ' + err);
217e41f4b71Sopenharmony_ci  }
218e41f4b71Sopenharmony_ci}
219e41f4b71Sopenharmony_ci```
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci## Obtaining Images and Videos in a User Album
222e41f4b71Sopenharmony_ci
223e41f4b71Sopenharmony_ci[Obtain the user album](#obtaining-a-user-album), and call [Album.getAssets](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getassets-3) to obtain the assets in the user album.
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ci**Prerequisites**
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained.
228e41f4b71Sopenharmony_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).
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ciExample: Obtain an image in the user album **albumName**.
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci**How to Develop**
233e41f4b71Sopenharmony_ci
234e41f4b71Sopenharmony_ci1. Set **albumFetchOptions** for obtaining the user album.
235e41f4b71Sopenharmony_ci2. Set **photoFetchOptions** for obtaining the image.
236e41f4b71Sopenharmony_ci3. Call **PhotoAccessHelper.getAlbums** to obtain user albums.
237e41f4b71Sopenharmony_ci4. Call [FetchResult.getFirstObject](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getfirstobject-1) to obtain the first user album.
238e41f4b71Sopenharmony_ci5. Call **Album.getAssets** to obtain the media assets in the user album.
239e41f4b71Sopenharmony_ci6. Call [FetchResult.getFirstObject](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getfirstobject-1) to obtain the first image from the result set.
240e41f4b71Sopenharmony_ci
241e41f4b71Sopenharmony_ci```ts
242e41f4b71Sopenharmony_ciimport dataSharePredicates from '@ohos.data.dataSharePredicates';
243e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper';
244e41f4b71Sopenharmony_ciconst context = getContext(this);
245e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
246e41f4b71Sopenharmony_ci
247e41f4b71Sopenharmony_ciasync function example() {
248e41f4b71Sopenharmony_ci  let albumPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
249e41f4b71Sopenharmony_ci  let albumName: photoAccessHelper.AlbumKeys = photoAccessHelper.AlbumKeys.ALBUM_NAME;
250e41f4b71Sopenharmony_ci  albumPredicates.equalTo(albumName, 'albumName');
251e41f4b71Sopenharmony_ci  let albumFetchOptions: photoAccessHelper.FetchOptions = {
252e41f4b71Sopenharmony_ci    fetchColumns: [],
253e41f4b71Sopenharmony_ci    predicates: albumPredicates
254e41f4b71Sopenharmony_ci  };
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci  let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
257e41f4b71Sopenharmony_ci  let photoFetchOptions: photoAccessHelper.FetchOptions = {
258e41f4b71Sopenharmony_ci    fetchColumns: [],
259e41f4b71Sopenharmony_ci    predicates: photoPredicates
260e41f4b71Sopenharmony_ci  };
261e41f4b71Sopenharmony_ci
262e41f4b71Sopenharmony_ci  try {
263e41f4b71Sopenharmony_ci    let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
264e41f4b71Sopenharmony_ci    let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
265e41f4b71Sopenharmony_ci    console.info('getAlbums successfully, albumName: ' + album.albumName);
266e41f4b71Sopenharmony_ci    let photoFetchResult = await album.getAssets(photoFetchOptions);
267e41f4b71Sopenharmony_ci    let photoAsset = await photoFetchResult.getFirstObject();
268e41f4b71Sopenharmony_ci    console.info('album getAssets successfully, albumName: ' + photoAsset.displayName);
269e41f4b71Sopenharmony_ci    albumFetchResult.close();
270e41f4b71Sopenharmony_ci    photoFetchResult.close();
271e41f4b71Sopenharmony_ci  } catch (err) {
272e41f4b71Sopenharmony_ci    console.error('album getAssets failed with err: ' + err);
273e41f4b71Sopenharmony_ci  }
274e41f4b71Sopenharmony_ci}
275e41f4b71Sopenharmony_ci```
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_ci## Removing Images and Videos from a User Album
278e41f4b71Sopenharmony_ci
279e41f4b71Sopenharmony_ci[Obtain the user album](#obtaining-a-user-album), and call [Album.getAssets](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getassets-3) to obtain the assets in the user album.
280e41f4b71Sopenharmony_ci
281e41f4b71Sopenharmony_ciSelect the assets to remove, and use [MediaAlbumChangeRequest.removeAssets](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#removeassets11) and [PhotoAccessHelper.applyChanges](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#applychanges11) to remove the selected media assets.
282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ci**Prerequisites**
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained.
286e41f4b71Sopenharmony_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).
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ciExample: Remove an image from the user album **albumName**.
289e41f4b71Sopenharmony_ci
290e41f4b71Sopenharmony_ci**How to Develop**
291e41f4b71Sopenharmony_ci
292e41f4b71Sopenharmony_ci1. Set **albumFetchOptions** for obtaining the user album.
293e41f4b71Sopenharmony_ci2. Set **photoFetchOptions** for obtaining the image.
294e41f4b71Sopenharmony_ci3. Call **PhotoAccessHelper.getAlbums** to obtain user albums.
295e41f4b71Sopenharmony_ci4. Call [FetchResult.getFirstObject](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getfirstobject-1) to obtain the first user album.
296e41f4b71Sopenharmony_ci5. Call **Album.getAssets** to obtain the media assets.
297e41f4b71Sopenharmony_ci6. Call [FetchResult.getFirstObject](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#getfirstobject-1) to obtain the first image from the result set.
298e41f4b71Sopenharmony_ci7. Call **MediaAlbumChangeRequest.removeAssets** to remove the image from the user album.
299e41f4b71Sopenharmony_ci8. Call **PhotoAccessHelper.applyChanges** to apply the changes.
300e41f4b71Sopenharmony_ci
301e41f4b71Sopenharmony_ci```ts
302e41f4b71Sopenharmony_ciimport dataSharePredicates from '@ohos.data.dataSharePredicates';
303e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper';
304e41f4b71Sopenharmony_ciconst context = getContext(this);
305e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
306e41f4b71Sopenharmony_ci
307e41f4b71Sopenharmony_ciasync function example() {
308e41f4b71Sopenharmony_ci  let albumPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
309e41f4b71Sopenharmony_ci  let albumName: photoAccessHelper.AlbumKeys = photoAccessHelper.AlbumKeys.ALBUM_NAME;
310e41f4b71Sopenharmony_ci  albumPredicates.equalTo(albumName, 'albumName');
311e41f4b71Sopenharmony_ci  let albumFetchOptions: photoAccessHelper.FetchOptions = {
312e41f4b71Sopenharmony_ci    fetchColumns: [],
313e41f4b71Sopenharmony_ci    predicates: albumPredicates
314e41f4b71Sopenharmony_ci  };
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_ci  let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
317e41f4b71Sopenharmony_ci  let photoFetchOptions: photoAccessHelper.FetchOptions = {
318e41f4b71Sopenharmony_ci    fetchColumns: [],
319e41f4b71Sopenharmony_ci    predicates: photoPredicates
320e41f4b71Sopenharmony_ci  };
321e41f4b71Sopenharmony_ci
322e41f4b71Sopenharmony_ci  try {
323e41f4b71Sopenharmony_ci    let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
324e41f4b71Sopenharmony_ci    let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
325e41f4b71Sopenharmony_ci    console.info('getAlbums successfully, albumName: ' + album.albumName);
326e41f4b71Sopenharmony_ci    let photoFetchResult = await album.getAssets(photoFetchOptions);
327e41f4b71Sopenharmony_ci    let photoAsset = await photoFetchResult.getFirstObject();
328e41f4b71Sopenharmony_ci    console.info('album getAssets successfully, albumName: ' + photoAsset.displayName);
329e41f4b71Sopenharmony_ci    let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album);
330e41f4b71Sopenharmony_ci    albumChangeRequest.removeAssets([photoAsset]);
331e41f4b71Sopenharmony_ci    await phAccessHelper.applyChanges(albumChangeRequest);
332e41f4b71Sopenharmony_ci    console.info('succeed to remove ' + photoAsset.displayName + ' from ' + album.albumName);
333e41f4b71Sopenharmony_ci    albumFetchResult.close();
334e41f4b71Sopenharmony_ci    photoFetchResult.close();
335e41f4b71Sopenharmony_ci  } catch (err) {
336e41f4b71Sopenharmony_ci    console.error('removeAssets failed with err: ' + err);
337e41f4b71Sopenharmony_ci  }
338e41f4b71Sopenharmony_ci}
339e41f4b71Sopenharmony_ci```
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ci<!--Del-->
342e41f4b71Sopenharmony_ci## Deleting a User Album (for System Applications Only)
343e41f4b71Sopenharmony_ci
344e41f4b71Sopenharmony_ci[Obtain the user album](#obtaining-a-user-album), and call [MediaAlbumChangeRequest.deleteAlbums](../../reference/apis-media-library-kit/js-apis-photoAccessHelper-sys.md#deletealbums11) to delete the user album.
345e41f4b71Sopenharmony_ci
346e41f4b71Sopenharmony_ci**Prerequisites**
347e41f4b71Sopenharmony_ci
348e41f4b71Sopenharmony_ci- A **PhotoAccessHelper** instance is obtained.
349e41f4b71Sopenharmony_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).
350e41f4b71Sopenharmony_ci
351e41f4b71Sopenharmony_ciExample: Delete the user album **albumName**.
352e41f4b71Sopenharmony_ci
353e41f4b71Sopenharmony_ci**How to Develop**
354e41f4b71Sopenharmony_ci
355e41f4b71Sopenharmony_ci1. Set **fetchOptions** for obtaining the user album.
356e41f4b71Sopenharmony_ci2. Call **PhotoAccessHelper.getAlbums** to obtain user albums.
357e41f4b71Sopenharmony_ci3. Call **FetchResult.getFirstObject** to obtain the first user album.
358e41f4b71Sopenharmony_ci4. Call **MediaAlbumChangeRequest.deleteAlbums** to delete the user album.
359e41f4b71Sopenharmony_ci
360e41f4b71Sopenharmony_ci```ts
361e41f4b71Sopenharmony_ciimport dataSharePredicates from '@ohos.data.dataSharePredicates';
362e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper';
363e41f4b71Sopenharmony_ciconst context = getContext(this);
364e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
365e41f4b71Sopenharmony_ci
366e41f4b71Sopenharmony_ciasync function example() {
367e41f4b71Sopenharmony_ci  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
368e41f4b71Sopenharmony_ci  let albumName: photoAccessHelper.AlbumKeys = photoAccessHelper.AlbumKeys.ALBUM_NAME;
369e41f4b71Sopenharmony_ci  predicates.equalTo(albumName, 'albumName');
370e41f4b71Sopenharmony_ci  let fetchOptions: photoAccessHelper.FetchOptions = {
371e41f4b71Sopenharmony_ci    fetchColumns: [],
372e41f4b71Sopenharmony_ci    predicates: predicates
373e41f4b71Sopenharmony_ci  };
374e41f4b71Sopenharmony_ci
375e41f4b71Sopenharmony_ci  try {
376e41f4b71Sopenharmony_ci    let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions);
377e41f4b71Sopenharmony_ci    let album: photoAccessHelper.Album = await fetchResult.getFirstObject();
378e41f4b71Sopenharmony_ci    console.info('getAlbums successfully, albumName: ' + album.albumName);
379e41f4b71Sopenharmony_ci    await photoAccessHelper.MediaAlbumChangeRequest.deleteAlbums(context, [album]);
380e41f4b71Sopenharmony_ci    fetchResult.close();
381e41f4b71Sopenharmony_ci  } catch (err) {
382e41f4b71Sopenharmony_ci    console.error('deleteAlbums failed with err: ' + err);
383e41f4b71Sopenharmony_ci  }
384e41f4b71Sopenharmony_ci}
385e41f4b71Sopenharmony_ci```
386e41f4b71Sopenharmony_ci<!--DelEnd-->
387