diff --git a/en/application-dev/file-management/photoAccessHelper-notify-guidelines.md b/en/application-dev/file-management/photoAccessHelper-notify-guidelines.md index b5a7f381053593a806b40d2214a5bb4777a1b83d..12e1f2c5beb2db4a666ad0cb7ec1b8b2989a071f 100644 --- a/en/application-dev/file-management/photoAccessHelper-notify-guidelines.md +++ b/en/application-dev/file-management/photoAccessHelper-notify-guidelines.md @@ -33,20 +33,21 @@ Example: Listener for changes of an image. When the image is favorited, the list ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); +let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo(photoAccessHelper.ImageVideoKey.DISPLAY_NAME, 'test.jpg'); -let fetchOptions = { +let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { - let fetchResult = await phAccessHelper.getAssets(fetchOptions); - let fileAsset = await fetchResult.getFirstObject(); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); + let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); console.info('getAssets fileAsset.uri : ' + fileAsset.uri); - let onCallback = (changeData) => { + let onCallback = (changeData:dataSharePredicates.ChangeData) => { console.info('onCallback successfully, changData: ' + JSON.stringify(changeData)); } phAccessHelper.registerChange(fileAsset.uri, false, onCallback); @@ -77,21 +78,22 @@ Example: Listener for a user album. When the album is renamed, the listener call ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); +let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME; predicates.equalTo(albumName, 'albumName'); -let fetchOptions = { +let fetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: predicates }; try { - let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); - let album = await fetchResult.getFirstObject(); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); + let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); console.info('getAlbums successfullyfully, albumName: ' + album.albumUri); - let onCallback = (changeData) => { + let onCallback = (changeData: photoAccessHelper.ChangeData) => { console.info('onCallback successfully, changData: ' + JSON.stringify(changeData)); } phAccessHelper.registerChange(album.albumUri, false, onCallback); @@ -133,21 +135,22 @@ Example: Register a listener for all file assets. When an observed file asset is ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let onCallback = (changeData) => { +let onCallback = (changeData: dataSharePredicates.ChangeData) => { console.info('onCallback successfully, changData: ' + JSON.stringify(changeData)); } phAccessHelper.registerChange(photoAccessHelper.DefaultChangeUri.DEFAULT_PHOTO_URI, true, onCallback); -let predicates = new dataSharePredicates.DataSharePredicates(); -let fetchOptions = { +let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { - let fetchResult = await phAccessHelper.getAssets(fetchOptions); - let fileAsset = await fetchResult.getFirstObject(); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); + let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); console.info('getAssets fileAsset.uri : ' + fileAsset.uri); await fileAsset.favorite(true); fetchResult.close(); @@ -175,23 +178,24 @@ Example: Unregister listening for an image. After that, the unregistered listene ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); +let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo(photoAccessHelper.ImageVideoKey.DISPLAY_NAME, 'test.jpg'); -let fetchOptions = { +let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { - let fetchResult = await phAccessHelper.getAssets(fetchOptions); - let fileAsset = await fetchResult.getFirstObject(); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); + let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); console.info('getAssets fileAsset.uri : ' + fileAsset.uri); - let onCallback1 = (changeData) => { + let onCallback1 = (changeData: photoAccessHelper.ChangeData) => { console.info('onCallback1, changData: ' + JSON.stringify(changeData)); } - let onCallback2 = (changeData) => { + let onCallback2 = (changeData: photoAccessHelper.ChangeData) => { console.info('onCallback2, changData: ' + JSON.stringify(changeData)); } phAccessHelper.registerChange(fileAsset.uri, false, onCallback1); diff --git a/en/application-dev/file-management/photoAccessHelper-overview.md b/en/application-dev/file-management/photoAccessHelper-overview.md index 8c66669b4e5992b1a23dd60e9c5f3ae4fe5fc5f0..e8317f562e6ea8f8b0948606cb2d42f1e164480c 100644 --- a/en/application-dev/file-management/photoAccessHelper-overview.md +++ b/en/application-dev/file-management/photoAccessHelper-overview.md @@ -49,7 +49,7 @@ import photoAccessHelper from '@ohos.file.photoAccessHelper'; // The phAccessHelper instance obtained here is a global object. By default, the object obtained here is used in subsequent operations in this document. If an undefined error is reported, add the code snippet here. const context = getContext(this); -let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); +let phAccessHelper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); ``` ## Applying for Permissions diff --git a/en/application-dev/file-management/photoAccessHelper-resource-guidelines.md b/en/application-dev/file-management/photoAccessHelper-resource-guidelines.md index a0557bcb2c264b2e1a641e489d2f62bf50deaf54..a517b4fb4cb1b6b2cd7711fdb68277292b7c6f7f 100644 --- a/en/application-dev/file-management/photoAccessHelper-resource-guidelines.md +++ b/en/application-dev/file-management/photoAccessHelper-resource-guidelines.md @@ -33,10 +33,11 @@ Example: Obtain the image **test.jpg**. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); +let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo(photoAccessHelper.PhotoKeys.DISPLAY_NAME, 'test.jpg'); -let fetchOptions = { +let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; @@ -45,9 +46,11 @@ let fetchOptions = { 2. Call **PhotoAccessHelper.getAssets** to obtain image assets. ```ts +import photoAccessHelper from '@ohos.file.photoAccessHelper'; + try { - let fetchResult = await phAccessHelper.getAssets(fetchOptions); - let fileAsset = await fetchResult.getFirstObject(); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); + let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); console.info('getAssets fileAsset.displayName : ' + fileAsset.displayName); fetchResult.close(); } catch (err) { @@ -61,10 +64,11 @@ Example: Obtain the image with the file URI **file://media/Photo/1**. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); +let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo(photoAccessHelper.PhotoKeys.URI, 'file://media/Photo/1'); -let fetchOptions = { +let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; @@ -73,9 +77,11 @@ let fetchOptions = { Call **PhotoAccessHelper.getAssets** to obtain image assets. ```ts +import photoAccessHelper from '@ohos.file.photoAccessHelper'; + try { - let fetchResult = await phAccessHelper.getAssets(fetchOptions); - let fileAsset = await fetchResult.getFirstObject(); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); + let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); console.info('getAssets fileAsset.uri : ' + fileAsset.uri); fetchResult.close(); } catch (err) { @@ -90,14 +96,15 @@ Example: Obtain the media assets added between 2022-06-01 and 2023-06-01. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); +let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let startTime = Date.parse(new Date('2022-06-01').toString()) / 1000; // The value of the start time is the number of seconds elapsed since the Epoch time. let endTime = Date.parse(new Date('2023-06-01').toString()) / 1000; // The value of the end time is the number of seconds elapsed since the Epoch time. -let date_added = photoAccessHelper.PhotoKeys.DATE_ADDED; +let date_added: photoAccessHelper.PhotoKeys = photoAccessHelper.PhotoKeys.DATE_ADDED; predicates.between(date_added, startTime, endTime); predicates.orderByDesc(date_added); // Sort the obtained records in descending order. -let fetchOptions = { +let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [date_added], // The date_added attribute is not a default option and needs to be added. predicates: predicates }; @@ -106,10 +113,12 @@ let fetchOptions = { Call **PhotoAccessHelper.getAssets** to obtain image assets. ```ts +import photoAccessHelper from '@ohos.file.photoAccessHelper'; + try { - let fetchResult = await phAccessHelper.getAssets(fetchOptions); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); console.info('getAssets count: ' + fetchResult.getCount()); - let fileAsset = await fetchResult.getFirstObject(); + let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); console.info('getAssets fileAsset.displayName : ' + fileAsset.displayName); fetchResult.close(); } catch (err) { @@ -142,16 +151,17 @@ Example: Obtain the thumbnail of 720 x 720 of an image. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); -let fetchOptions = { +let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let fetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: predicates }; try { - let fetchResult = await phAccessHelper.getAssets(fetchOptions); - let fileAsset = await fetchResult.getFirstObject(); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); + let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); console.info('getAssets fileAsset.displayName : ' + fileAsset.displayName); let size = { width: 720, height: 720 }; let pixelMap = await fileAsset.getThumbnail(size); @@ -182,9 +192,11 @@ Example: Create an image asset. 2. Call **createAsset** to create an image asset. ```ts +import photoAccessHelper from '@ohos.file.photoAccessHelper'; + try { let displayName = 'testPhoto' + Date.now() + '.jpg'; - let createOption = { + let createOption: photoAccessHelper.CreateOptions = { subType: photoAccessHelper.PhotoSubtype.DEFAULT }; @@ -220,19 +232,20 @@ Example: Rename the first file in the obtained image assets. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); -let fetchOptions = { +let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let fetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: ['title'], predicates: predicates }; let newTitle = 'newTestPhoto'; try { - let fetchResult = await phAccessHelper.getAssets(fetchOptions); - let fileAsset = await fetchResult.getFirstObject(); - let title = photoAccessHelper.PhotoKeys.TITLE; - let fileAssetTitle = fileAsset.get(title); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); + let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); + let title: photoAccessHelper.PhotoKeys = photoAccessHelper.PhotoKeys.TITLE; + let fileAssetTitle: photoAccessHelper.MemberType = fileAsset.get(title); console.info('getAssets fileAsset.title : ' + fileAssetTitle); fileAsset.set(title, newTitle); await fileAsset.commitModify(); @@ -264,16 +277,17 @@ Example: Move the first file in the result set to the trash. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); -let fetchOptions = { +let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let fetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: predicates }; try { - let fetchResult = await phAccessHelper.getAssets(fetchOptions); - let fileAsset = await fetchResult.getFirstObject(); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); + let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); console.info('getAssets fileAsset.uri : ' + fileAsset.uri); await phAccessHelper.deleteAssets([fileAsset.uri]); fetchResult.close(); diff --git a/en/application-dev/file-management/photoAccessHelper-systemAlbum-guidelines.md b/en/application-dev/file-management/photoAccessHelper-systemAlbum-guidelines.md index e42d7bab28aa84d141bcc4fe385618bfd16114ca..19c3434cca92143b5ff3fc104a81762c934b9e9b 100644 --- a/en/application-dev/file-management/photoAccessHelper-systemAlbum-guidelines.md +++ b/en/application-dev/file-management/photoAccessHelper-systemAlbum-guidelines.md @@ -29,9 +29,11 @@ Use [getAlbums](../reference/apis/js-apis-photoAccessHelper.md#getalbums) to obt 2. Call **getAlbums** to obtain a **Favorites** object. ```ts +import photoAccessHelper from '@ohos.file.photoAccessHelper'; + try { - let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE); - let album = await fetchResult.getFirstObject(); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE); + let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); console.info('get favorite Album successfully, albumUri: ' + album.albumUri); fetchResult.close(); } catch (err) { @@ -58,16 +60,17 @@ Example: Favorite an image. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); +let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo(photoAccessHelper.ImageVideoKey.DISPLAY_NAME, 'test.jpg'); -let fetchOptions = { +let fetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: predicates }; try { - let photoFetchResult = await phAccessHelper.getAssets(fetchOptions); + let photoFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let fileAsset = await photoFetchResult.getFirstObject(); console.info('getAssets fileAsset.displayName : ' + fileAsset.displayName); let favoriteState = true; @@ -97,16 +100,17 @@ Example: Obtain an image from **Favorites**. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); -let fetchOptions = { +let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let fetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: predicates }; try { - let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE); - let album = await albumFetchResult.getFirstObject(); + let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE); + let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); console.info('get favorite Album successfully, albumUri: ' + album.albumUri); let photoFetchResult = await album.getAssets(fetchOptions); @@ -139,16 +143,17 @@ Example: Unfavorite an image. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); -let fetchOptions = { +let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let fetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: predicates }; try { - let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE); - let album = await albumFetchResult.getFirstObject(); + let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE); + let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); console.info('get favorite Album successfully, albumUri: ' + album.albumUri); let photoFetchResult = await album.getAssets(fetchOptions); @@ -182,9 +187,11 @@ Use [getAlbums](../reference/apis/js-apis-photoAccessHelper.md#getalbums) to obt 2. Use **getAlbums** to obtain the video album object. ```ts +import photoAccessHelper from '@ohos.file.photoAccessHelper'; + try { - let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.VIDEO); - let album = await fetchResult.getFirstObject(); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.VIDEO); + let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); console.info('get video Album successfully, albumUri: ' + album.albumUri); fetchResult.close(); } catch (err) { @@ -212,16 +219,17 @@ Example: Obtain a video in **Videos**. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); -let fetchOptions = { +let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let fetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: predicates }; try { - let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.VIDEO); - let album = await albumFetchResult.getFirstObject(); + let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.VIDEO); + let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); console.info('get video Album successfully, albumUri: ' + album.albumUri); let videoFetchResult = await album.getAssets(fetchOptions); @@ -253,9 +261,11 @@ Use [getAlbums](../reference/apis/js-apis-photoAccessHelper.md#getalbums) to obt 2. Use **getAlbums** to obtain a screenshot album object. ```ts +import photoAccessHelper from '@ohos.file.photoAccessHelper'; + try { - let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.SCREENSHOT); - let album = await fetchResult.getFirstObject(); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.SCREENSHOT); + let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); console.info('get screenshot Album successfully, albumUri: ' + album.albumUri); fetchResult.close(); } catch (err) { @@ -283,16 +293,17 @@ Example: Obtain a media asset from **Screenshots**. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); -let fetchOptions = { +let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let fetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: predicates }; try { - let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.SCREENSHOT); - let album = await albumFetchResult.getFirstObject(); + let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.SCREENSHOT); + let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); console.info('get screenshot album successfully, albumUri: ' + album.albumUri); let screenshotFetchResult = await album.getAssets(fetchOptions); diff --git a/en/application-dev/file-management/photoAccessHelper-userAlbum-guidelines.md b/en/application-dev/file-management/photoAccessHelper-userAlbum-guidelines.md index 87d0fa3517e1ca3fcc6e4e494b5e0bcff229b80a..db6c3a8058cef3e921b6ce15c5df09bac0cb6b5f 100644 --- a/en/application-dev/file-management/photoAccessHelper-userAlbum-guidelines.md +++ b/en/application-dev/file-management/photoAccessHelper-userAlbum-guidelines.md @@ -34,9 +34,11 @@ Example: Create a user album. 2. Use **createAlbum** to create an album. ```ts +import photoAccessHelper from '@ohos.file.photoAccessHelper'; + try { - let albumName = 'albumName'; - let album = await phAccessHelper.createAlbum(albumName); + let albumName: photoAccessHelper.AlbumName = 'albumName'; + let album: photoAccessHelper.Album = await phAccessHelper.createAlbum(albumName); console.info('createAlbum successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri); } catch (err) { console.error('createAlbum failed with err: ' + err); @@ -62,18 +64,19 @@ Example: Obtain the user album named **albumName**. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); -let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME; +let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME; predicates.equalTo(albumName, 'albumName'); -let fetchOptions = { +let fetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: predicates }; try { - let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); - let album = await fetchResult.getFirstObject(); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); + let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); console.info('getAlbums successfully, albumName: ' + album.albumName); fetchResult.close(); } catch (err) { @@ -106,18 +109,19 @@ Example: Rename an album named **albumName**. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); -let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME; +let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME; predicates.equalTo(albumName, 'albumName'); -let fetchOptions = { +let fetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: predicates }; try { - let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); - let album = await fetchResult.getFirstObject(); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); + let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); console.info('getAlbums successfully, albumName: ' + album.albumName); album.albumName = 'newAlbumName'; await album.commitModify(); @@ -150,24 +154,25 @@ Example: Add an image to the album **albumName**. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let albumPredicates = new dataSharePredicates.DataSharePredicates(); -let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME; +let albumPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME; albumPredicates.equalTo(albumName, 'albumName'); -let albumFetchOptions = { +let albumFetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: albumPredicates }; -let photoPredicates = new dataSharePredicates.DataSharePredicates(); -let photoFetchOptions = { +let photoPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let photoFetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: photoPredicates }; try { - let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); - let album = await albumFetchResult.getFirstObject(); + let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); + let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); console.info('getAlbums successfully, albumName: ' + album.albumName); let photoFetchResult = await phAccessHelper.getAssets(photoFetchOptions); let fileAsset = await photoFetchResult.getFirstObject(); @@ -202,24 +207,25 @@ Example: Obtain an image in the user album **albumName**. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let albumPredicates = new dataSharePredicates.DataSharePredicates(); -let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME; +let albumPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME; albumPredicates.equalTo(albumName, 'albumName'); -let albumFetchOptions = { +let albumFetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: albumPredicates }; -let photoPredicates = new dataSharePredicates.DataSharePredicates(); -let photoFetchOptions = { +let photoPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let photoFetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: photoPredicates }; try { - let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); - let album = await albumFetchResult.getFirstObject(); + let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); + let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); console.info('getAlbums successfully, albumName: ' + album.albumName); let photoFetchResult = await album.getAssets(photoFetchOptions); let fileAsset = await photoFetchResult.getFirstObject(); @@ -256,24 +262,25 @@ Example: Remove an image from the album named **albumName**. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let albumPredicates = new dataSharePredicates.DataSharePredicates(); -let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME; +let albumPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME; albumPredicates.equalTo(albumName, 'albumName'); -let albumFetchOptions = { +let albumFetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: albumPredicates }; -let photoPredicates = new dataSharePredicates.DataSharePredicates(); -let photoFetchOptions = { +let photoPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let photoFetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: photoPredicates }; try { - let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); - let album = await albumFetchResult.getFirstObject(); + let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); + let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); console.info('getAlbums successfully, albumName: ' + album.albumName); let photoFetchResult = await album.getAssets(photoFetchOptions); let fileAsset = await photoFetchResult.getFirstObject(); @@ -306,18 +313,19 @@ Example: Delete a user album named **albumName**. ```ts import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; -let predicates = new dataSharePredicates.DataSharePredicates(); -let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME; +let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates(); +let albumName: photoAccessHelper.AlbumName = photoAccessHelper.AlbumKey.ALBUM_NAME; predicates.equalTo(albumName, '%albumName%'); -let fetchOptions = { +let fetchOptions: dataSharePredicates.FetchOptions = { fetchColumns: [], predicates: predicates }; try { - let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); - let album = await fetchResult.getFirstObject(); + let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); + let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); console.info('getAlbums successfully, albumName: ' + album.albumName); phAccessHelper.deleteAlbums([album]); fetchResult.close();