1# Interface (Album) 2 3> **NOTE** 4> 5> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 6 7Album extends [AbsAlbum](arkts-apis-photoAccessHelper-AbsAlbum.md). 8 9Album provides APIs to manage albums. 10 11## Modules to Import 12 13```ts 14import { photoAccessHelper } from '@kit.MediaLibraryKit'; 15``` 16 17## Properties 18 19**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 20 21| Name | Type | Readable | Writable | Description | 22| ------------ | ------ | ---- | ---- | ------- | 23| imageCount<sup>11+</sup> | number | Yes | No | Number of images in the album.| 24| videoCount<sup>11+</sup> | number | Yes | No | Number of videos in the album.| 25 26## commitModify 27 28commitModify(callback: AsyncCallback<void>): void 29 30Commits the modification on the album attributes to the database. This API uses an asynchronous callback to return the result. 31 32**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 33 34**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 35 36**Parameters** 37 38| Name | Type | Mandatory| Description | 39| -------- | ------------------------- | ---- | ---------- | 40| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 41 42**Error codes** 43 44For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 45 46 47| ID| Error Message| 48| -------- | ---------------------------------------- | 49| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 50| 201 | Permission denied. | 51| 13900020 | Invalid argument. | 52| 14000011 | System inner fail. | 53 54**Example** 55 56For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). 57 58```ts 59import { dataSharePredicates } from '@kit.ArkData'; 60 61async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 62 console.info('albumCommitModifyDemo'); 63 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 64 let albumFetchOptions: photoAccessHelper.FetchOptions = { 65 fetchColumns: [], 66 predicates: predicates 67 }; 68 let albumList: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); 69 let album: photoAccessHelper.Album = await albumList.getFirstObject(); 70 album.albumName = 'hello'; 71 album.commitModify((err) => { 72 if (err !== undefined) { 73 console.error(`commitModify failed with error: ${err.code}, ${err.message}`); 74 } else { 75 console.info('commitModify successfully'); 76 } 77 }); 78} 79``` 80 81## commitModify 82 83commitModify(): Promise<void> 84 85Commits the modification on the album attributes to the database. This API uses a promise to return the result. 86 87**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 88 89**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 90 91**Return value** 92 93| Type | Description | 94| ------------------- | ------------ | 95| Promise<void> | Promise that returns no value.| 96 97**Error codes** 98 99For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 100 101 102| ID| Error Message| 103| -------- | ---------------------------------------- | 104| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 105| 201 | Permission denied. | 106| 13900020 | Invalid argument. | 107| 14000011 | System inner fail. | 108 109**Example** 110 111For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). 112 113```ts 114import { dataSharePredicates } from '@kit.ArkData'; 115import { BusinessError } from '@kit.BasicServicesKit'; 116 117async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 118 console.info('albumCommitModifyDemo'); 119 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 120 let albumFetchOptions: photoAccessHelper.FetchOptions = { 121 fetchColumns: [], 122 predicates: predicates 123 }; 124 let albumList: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); 125 let album: photoAccessHelper.Album = await albumList.getFirstObject(); 126 album.albumName = 'hello'; 127 album.commitModify().then(() => { 128 console.info('commitModify successfully'); 129 }).catch((err: BusinessError) => { 130 console.error(`commitModify failed with error: ${err.code}, ${err.message}`); 131 }); 132} 133``` 134 135## addAssets<sup>(deprecated)</sup> 136 137addAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 138 139Adds image and video assets to a user album. Before the operation, ensure that the image and video assets to add and the album exist. This API uses an asynchronous callback to return the result. 140 141> **NOTE** 142> 143> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [MediaAlbumChangeRequest.addAssets](arkts-apis-photoAccessHelper-MediaAlbumChangeRequest.md#addassets11) instead. 144 145**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 146 147**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 148 149**Parameters** 150 151| Name | Type | Mandatory| Description | 152| -------- | ------------------------- | ---- | ---------- | 153| assets | Array<[PhotoAsset](arkts-apis-photoAccessHelper-PhotoAsset.md)> | Yes | Array of the image and video assets to add.| 154| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 155 156**Error codes** 157 158For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 159 160 161| ID| Error Message| 162| -------- | ---------------------------------------- | 163| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 164| 201 | Permission denied. | 165| 13900020 | Invalid argument. | 166| 14000011 | System inner fail. | 167 168**Example** 169 170For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). 171 172```ts 173import { dataSharePredicates } from '@kit.ArkData'; 174 175async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 176 try { 177 console.info('addAssetsDemoCallback'); 178 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 179 let fetchOption: photoAccessHelper.FetchOptions = { 180 fetchColumns: [], 181 predicates: predicates 182 }; 183 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 184 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 185 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 186 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 187 album.addAssets([asset], (err) => { 188 if (err === undefined) { 189 console.info('album addAssets successfully'); 190 } else { 191 console.error(`album addAssets failed with error: ${err.code}, ${err.message}`); 192 } 193 }); 194 } catch (err) { 195 console.error(`addAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); 196 } 197} 198``` 199 200## addAssets<sup>(deprecated)</sup> 201 202addAssets(assets: Array<PhotoAsset>): Promise<void> 203 204Adds image and video assets to a user album. Before the operation, ensure that the image and video assets to add and the album exist. This API uses a promise to return the result. 205 206> **NOTE** 207> 208> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [MediaAlbumChangeRequest.addAssets](arkts-apis-photoAccessHelper-MediaAlbumChangeRequest.md#addassets11) instead. 209 210**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 211 212**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 213 214**Parameters** 215 216| Name | Type | Mandatory| Description | 217| -------- | ------------------------- | ---- | ---------- | 218| assets | Array<[PhotoAsset](arkts-apis-photoAccessHelper-PhotoAsset.md)> | Yes | Array of the image and video assets to add.| 219 220**Return value** 221 222| Type | Description | 223| --------------------------------------- | ----------------- | 224|Promise<void> | Promise that returns no value.| 225 226**Error codes** 227 228For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 229 230 231| ID| Error Message| 232| -------- | ---------------------------------------- | 233| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 234| 201 | Permission denied. | 235| 13900020 | Invalid argument. | 236| 14000011 | System inner fail. | 237 238**Example** 239 240For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). 241 242```ts 243import { dataSharePredicates } from '@kit.ArkData'; 244import { BusinessError } from '@kit.BasicServicesKit'; 245 246async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 247 try { 248 console.info('addAssetsDemoPromise'); 249 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 250 let fetchOption: photoAccessHelper.FetchOptions = { 251 fetchColumns: [], 252 predicates: predicates 253 }; 254 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 255 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 256 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 257 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 258 album.addAssets([asset]).then(() => { 259 console.info('album addAssets successfully'); 260 }).catch((err: BusinessError) => { 261 console.error(`album addAssets failed with error: ${err.code}, ${err.message}`); 262 }); 263 } catch (err) { 264 console.error(`addAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); 265 } 266} 267``` 268 269## removeAssets<sup>(deprecated)</sup> 270 271removeAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 272 273Removes image and video assets from a user album. The album and file resources must exist. This API uses an asynchronous callback to return the result. 274 275> **NOTE** 276> 277> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [MediaAlbumChangeRequest.removeAssets](arkts-apis-photoAccessHelper-MediaAlbumChangeRequest.md#removeassets11) instead. 278 279**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 280 281**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 282 283**Parameters** 284 285| Name | Type | Mandatory| Description | 286| -------- | ------------------------- | ---- | ---------- | 287| assets | Array<[PhotoAsset](arkts-apis-photoAccessHelper-PhotoAsset.md)> | Yes | Array of the image and video assets to remove.| 288| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 289 290**Error codes** 291 292For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 293 294 295| ID| Error Message| 296| -------- | ---------------------------------------- | 297| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 298| 201 | Permission denied. | 299| 13900020 | Invalid argument. | 300| 14000011 | System inner fail. | 301 302**Example** 303 304For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). 305 306```ts 307import { dataSharePredicates } from '@kit.ArkData'; 308 309async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 310 try { 311 console.info('removeAssetsDemoCallback'); 312 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 313 let fetchOption: photoAccessHelper.FetchOptions = { 314 fetchColumns: [], 315 predicates: predicates 316 }; 317 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 318 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 319 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 320 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 321 album.removeAssets([asset], (err) => { 322 if (err === undefined) { 323 console.info('album removeAssets successfully'); 324 } else { 325 console.error(`album removeAssets failed with error: ${err.code}, ${err.message}`); 326 } 327 }); 328 } catch (err) { 329 console.error(`removeAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); 330 } 331} 332``` 333 334## removeAssets<sup>(deprecated)</sup> 335 336removeAssets(assets: Array<PhotoAsset>): Promise<void> 337 338Removes image and video assets from a user album. The album and file resources must exist. This API uses a promise to return the result. 339 340> **NOTE** 341> 342> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [MediaAlbumChangeRequest.removeAssets](arkts-apis-photoAccessHelper-MediaAlbumChangeRequest.md#removeassets11) instead. 343 344**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 345 346**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 347 348**Parameters** 349 350| Name | Type | Mandatory| Description | 351| -------- | ------------------------- | ---- | ---------- | 352| assets | Array<[PhotoAsset](arkts-apis-photoAccessHelper-PhotoAsset.md)> | Yes | Array of the image and video assets to remove.| 353 354**Return value** 355 356| Type | Description | 357| --------------------------------------- | ----------------- | 358|Promise<void> | Promise that returns no value.| 359 360**Error codes** 361 362For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 363 364 365| ID| Error Message| 366| -------- | ---------------------------------------- | 367| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 368| 201 | Permission denied. | 369| 13900020 | Invalid argument. | 370| 14000011 | System inner fail. | 371 372**Example** 373 374For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). 375 376```ts 377import { dataSharePredicates } from '@kit.ArkData'; 378import { BusinessError } from '@kit.BasicServicesKit'; 379 380async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 381 try { 382 console.info('removeAssetsDemoPromise'); 383 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 384 let fetchOption: photoAccessHelper.FetchOptions = { 385 fetchColumns: [], 386 predicates: predicates 387 }; 388 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 389 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 390 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 391 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 392 album.removeAssets([asset]).then(() => { 393 console.info('album removeAssets successfully'); 394 }).catch((err: BusinessError) => { 395 console.error(`album removeAssets failed with error: ${err.code}, ${err.message}`); 396 }); 397 } catch (err) { 398 console.error(`removeAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); 399 } 400} 401``` 402