未验证 提交 4a2d0e4e 编写于 作者: O openharmony_ci 提交者: Gitee

!22790 photoaccesshelper接口文档修改

Merge pull request !22790 from 牛雨欣/master
...@@ -33,20 +33,21 @@ Example: Listener for changes of an image. When the image is favorited, the list ...@@ -33,20 +33,21 @@ Example: Listener for changes of an image. When the image is favorited, the list
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; 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'); predicates.equalTo(photoAccessHelper.ImageVideoKey.DISPLAY_NAME, 'test.jpg');
let fetchOptions = { let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
try { try {
let fetchResult = await phAccessHelper.getAssets(fetchOptions); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject(); let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
console.info('getAssets fileAsset.uri : ' + fileAsset.uri); console.info('getAssets fileAsset.uri : ' + fileAsset.uri);
let onCallback = (changeData) => { let onCallback = (changeData:dataSharePredicates.ChangeData) => {
console.info('onCallback successfully, changData: ' + JSON.stringify(changeData)); console.info('onCallback successfully, changData: ' + JSON.stringify(changeData));
} }
phAccessHelper.registerChange(fileAsset.uri, false, onCallback); phAccessHelper.registerChange(fileAsset.uri, false, onCallback);
...@@ -77,21 +78,22 @@ Example: Listener for a user album. When the album is renamed, the listener call ...@@ -77,21 +78,22 @@ Example: Listener for a user album. When the album is renamed, the listener call
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; 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; let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME;
predicates.equalTo(albumName, 'albumName'); predicates.equalTo(albumName, 'albumName');
let fetchOptions = { let fetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
try { try {
let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions);
let album = await fetchResult.getFirstObject(); let album: photoAccessHelper.Album = await fetchResult.getFirstObject();
console.info('getAlbums successfullyfully, albumName: ' + album.albumUri); console.info('getAlbums successfullyfully, albumName: ' + album.albumUri);
let onCallback = (changeData) => { let onCallback = (changeData: photoAccessHelper.ChangeData) => {
console.info('onCallback successfully, changData: ' + JSON.stringify(changeData)); console.info('onCallback successfully, changData: ' + JSON.stringify(changeData));
} }
phAccessHelper.registerChange(album.albumUri, false, onCallback); phAccessHelper.registerChange(album.albumUri, false, onCallback);
...@@ -133,21 +135,22 @@ Example: Register a listener for all file assets. When an observed file asset is ...@@ -133,21 +135,22 @@ Example: Register a listener for all file assets. When an observed file asset is
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; 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)); console.info('onCallback successfully, changData: ' + JSON.stringify(changeData));
} }
phAccessHelper.registerChange(photoAccessHelper.DefaultChangeUri.DEFAULT_PHOTO_URI, true, onCallback); phAccessHelper.registerChange(photoAccessHelper.DefaultChangeUri.DEFAULT_PHOTO_URI, true, onCallback);
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions = { let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
try { try {
let fetchResult = await phAccessHelper.getAssets(fetchOptions); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject(); let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
console.info('getAssets fileAsset.uri : ' + fileAsset.uri); console.info('getAssets fileAsset.uri : ' + fileAsset.uri);
await fileAsset.favorite(true); await fileAsset.favorite(true);
fetchResult.close(); fetchResult.close();
...@@ -175,23 +178,24 @@ Example: Unregister listening for an image. After that, the unregistered listene ...@@ -175,23 +178,24 @@ Example: Unregister listening for an image. After that, the unregistered listene
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; 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'); predicates.equalTo(photoAccessHelper.ImageVideoKey.DISPLAY_NAME, 'test.jpg');
let fetchOptions = { let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
try { try {
let fetchResult = await phAccessHelper.getAssets(fetchOptions); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject(); let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
console.info('getAssets fileAsset.uri : ' + fileAsset.uri); console.info('getAssets fileAsset.uri : ' + fileAsset.uri);
let onCallback1 = (changeData) => { let onCallback1 = (changeData: photoAccessHelper.ChangeData) => {
console.info('onCallback1, changData: ' + JSON.stringify(changeData)); console.info('onCallback1, changData: ' + JSON.stringify(changeData));
} }
let onCallback2 = (changeData) => { let onCallback2 = (changeData: photoAccessHelper.ChangeData) => {
console.info('onCallback2, changData: ' + JSON.stringify(changeData)); console.info('onCallback2, changData: ' + JSON.stringify(changeData));
} }
phAccessHelper.registerChange(fileAsset.uri, false, onCallback1); phAccessHelper.registerChange(fileAsset.uri, false, onCallback1);
......
...@@ -49,7 +49,7 @@ import photoAccessHelper from '@ohos.file.photoAccessHelper'; ...@@ -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. // 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); const context = getContext(this);
let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); let phAccessHelper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
``` ```
## Applying for Permissions ## Applying for Permissions
......
...@@ -33,10 +33,11 @@ Example: Obtain the image **test.jpg**. ...@@ -33,10 +33,11 @@ Example: Obtain the image **test.jpg**.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; 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'); predicates.equalTo(photoAccessHelper.PhotoKeys.DISPLAY_NAME, 'test.jpg');
let fetchOptions = { let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
...@@ -45,9 +46,11 @@ let fetchOptions = { ...@@ -45,9 +46,11 @@ let fetchOptions = {
2. Call **PhotoAccessHelper.getAssets** to obtain image assets. 2. Call **PhotoAccessHelper.getAssets** to obtain image assets.
```ts ```ts
import photoAccessHelper from '@ohos.file.photoAccessHelper';
try { try {
let fetchResult = await phAccessHelper.getAssets(fetchOptions); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject(); let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
console.info('getAssets fileAsset.displayName : ' + fileAsset.displayName); console.info('getAssets fileAsset.displayName : ' + fileAsset.displayName);
fetchResult.close(); fetchResult.close();
} catch (err) { } catch (err) {
...@@ -61,10 +64,11 @@ Example: Obtain the image with the file URI **file://media/Photo/1**. ...@@ -61,10 +64,11 @@ Example: Obtain the image with the file URI **file://media/Photo/1**.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; 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'); predicates.equalTo(photoAccessHelper.PhotoKeys.URI, 'file://media/Photo/1');
let fetchOptions = { let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
...@@ -73,9 +77,11 @@ let fetchOptions = { ...@@ -73,9 +77,11 @@ let fetchOptions = {
Call **PhotoAccessHelper.getAssets** to obtain image assets. Call **PhotoAccessHelper.getAssets** to obtain image assets.
```ts ```ts
import photoAccessHelper from '@ohos.file.photoAccessHelper';
try { try {
let fetchResult = await phAccessHelper.getAssets(fetchOptions); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject(); let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
console.info('getAssets fileAsset.uri : ' + fileAsset.uri); console.info('getAssets fileAsset.uri : ' + fileAsset.uri);
fetchResult.close(); fetchResult.close();
} catch (err) { } catch (err) {
...@@ -90,14 +96,15 @@ Example: Obtain the media assets added between 2022-06-01 and 2023-06-01. ...@@ -90,14 +96,15 @@ Example: Obtain the media assets added between 2022-06-01 and 2023-06-01.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; 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 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 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.between(date_added, startTime, endTime);
predicates.orderByDesc(date_added); // Sort the obtained records in descending order. 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. fetchColumns: [date_added], // The date_added attribute is not a default option and needs to be added.
predicates: predicates predicates: predicates
}; };
...@@ -106,10 +113,12 @@ let fetchOptions = { ...@@ -106,10 +113,12 @@ let fetchOptions = {
Call **PhotoAccessHelper.getAssets** to obtain image assets. Call **PhotoAccessHelper.getAssets** to obtain image assets.
```ts ```ts
import photoAccessHelper from '@ohos.file.photoAccessHelper';
try { try {
let fetchResult = await phAccessHelper.getAssets(fetchOptions); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
console.info('getAssets count: ' + fetchResult.getCount()); 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); console.info('getAssets fileAsset.displayName : ' + fileAsset.displayName);
fetchResult.close(); fetchResult.close();
} catch (err) { } catch (err) {
...@@ -142,16 +151,17 @@ Example: Obtain the thumbnail of 720 x 720 of an image. ...@@ -142,16 +151,17 @@ Example: Obtain the thumbnail of 720 x 720 of an image.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; 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 fetchOptions = { let fetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
try { try {
let fetchResult = await phAccessHelper.getAssets(fetchOptions); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject(); let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
console.info('getAssets fileAsset.displayName : ' + fileAsset.displayName); console.info('getAssets fileAsset.displayName : ' + fileAsset.displayName);
let size = { width: 720, height: 720 }; let size = { width: 720, height: 720 };
let pixelMap = await fileAsset.getThumbnail(size); let pixelMap = await fileAsset.getThumbnail(size);
...@@ -182,9 +192,11 @@ Example: Create an image asset. ...@@ -182,9 +192,11 @@ Example: Create an image asset.
2. Call **createAsset** to create an image asset. 2. Call **createAsset** to create an image asset.
```ts ```ts
import photoAccessHelper from '@ohos.file.photoAccessHelper';
try { try {
let displayName = 'testPhoto' + Date.now() + '.jpg'; let displayName = 'testPhoto' + Date.now() + '.jpg';
let createOption = { let createOption: photoAccessHelper.CreateOptions = {
subType: photoAccessHelper.PhotoSubtype.DEFAULT subType: photoAccessHelper.PhotoSubtype.DEFAULT
}; };
...@@ -220,19 +232,20 @@ Example: Rename the first file in the obtained image assets. ...@@ -220,19 +232,20 @@ Example: Rename the first file in the obtained image assets.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; 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 fetchOptions = { let fetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: ['title'], fetchColumns: ['title'],
predicates: predicates predicates: predicates
}; };
let newTitle = 'newTestPhoto'; let newTitle = 'newTestPhoto';
try { try {
let fetchResult = await phAccessHelper.getAssets(fetchOptions); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject(); let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
let title = photoAccessHelper.PhotoKeys.TITLE; let title: photoAccessHelper.PhotoKeys = photoAccessHelper.PhotoKeys.TITLE;
let fileAssetTitle = fileAsset.get(title); let fileAssetTitle: photoAccessHelper.MemberType = fileAsset.get(title);
console.info('getAssets fileAsset.title : ' + fileAssetTitle); console.info('getAssets fileAsset.title : ' + fileAssetTitle);
fileAsset.set(title, newTitle); fileAsset.set(title, newTitle);
await fileAsset.commitModify(); await fileAsset.commitModify();
...@@ -264,16 +277,17 @@ Example: Move the first file in the result set to the trash. ...@@ -264,16 +277,17 @@ Example: Move the first file in the result set to the trash.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; 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 fetchOptions = { let fetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
try { try {
let fetchResult = await phAccessHelper.getAssets(fetchOptions); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject(); let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
console.info('getAssets fileAsset.uri : ' + fileAsset.uri); console.info('getAssets fileAsset.uri : ' + fileAsset.uri);
await phAccessHelper.deleteAssets([fileAsset.uri]); await phAccessHelper.deleteAssets([fileAsset.uri]);
fetchResult.close(); fetchResult.close();
......
...@@ -29,9 +29,11 @@ Use [getAlbums](../reference/apis/js-apis-photoAccessHelper.md#getalbums) to obt ...@@ -29,9 +29,11 @@ Use [getAlbums](../reference/apis/js-apis-photoAccessHelper.md#getalbums) to obt
2. Call **getAlbums** to obtain a **Favorites** object. 2. Call **getAlbums** to obtain a **Favorites** object.
```ts ```ts
import photoAccessHelper from '@ohos.file.photoAccessHelper';
try { try {
let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE);
let album = await fetchResult.getFirstObject(); let album: photoAccessHelper.Album = await fetchResult.getFirstObject();
console.info('get favorite Album successfully, albumUri: ' + album.albumUri); console.info('get favorite Album successfully, albumUri: ' + album.albumUri);
fetchResult.close(); fetchResult.close();
} catch (err) { } catch (err) {
...@@ -58,16 +60,17 @@ Example: Favorite an image. ...@@ -58,16 +60,17 @@ Example: Favorite an image.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; 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'); predicates.equalTo(photoAccessHelper.ImageVideoKey.DISPLAY_NAME, 'test.jpg');
let fetchOptions = { let fetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
try { try {
let photoFetchResult = await phAccessHelper.getAssets(fetchOptions); let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await photoFetchResult.getFirstObject(); let fileAsset = await photoFetchResult.getFirstObject();
console.info('getAssets fileAsset.displayName : ' + fileAsset.displayName); console.info('getAssets fileAsset.displayName : ' + fileAsset.displayName);
let favoriteState = true; let favoriteState = true;
...@@ -97,16 +100,17 @@ Example: Obtain an image from **Favorites**. ...@@ -97,16 +100,17 @@ Example: Obtain an image from **Favorites**.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions = { let fetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
try { try {
let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE); let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE);
let album = await albumFetchResult.getFirstObject(); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
console.info('get favorite Album successfully, albumUri: ' + album.albumUri); console.info('get favorite Album successfully, albumUri: ' + album.albumUri);
let photoFetchResult = await album.getAssets(fetchOptions); let photoFetchResult = await album.getAssets(fetchOptions);
...@@ -139,16 +143,17 @@ Example: Unfavorite an image. ...@@ -139,16 +143,17 @@ Example: Unfavorite an image.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions = { let fetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
try { try {
let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE); let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE);
let album = await albumFetchResult.getFirstObject(); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
console.info('get favorite Album successfully, albumUri: ' + album.albumUri); console.info('get favorite Album successfully, albumUri: ' + album.albumUri);
let photoFetchResult = await album.getAssets(fetchOptions); let photoFetchResult = await album.getAssets(fetchOptions);
...@@ -182,9 +187,11 @@ Use [getAlbums](../reference/apis/js-apis-photoAccessHelper.md#getalbums) to obt ...@@ -182,9 +187,11 @@ Use [getAlbums](../reference/apis/js-apis-photoAccessHelper.md#getalbums) to obt
2. Use **getAlbums** to obtain the video album object. 2. Use **getAlbums** to obtain the video album object.
```ts ```ts
import photoAccessHelper from '@ohos.file.photoAccessHelper';
try { try {
let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.VIDEO); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.VIDEO);
let album = await fetchResult.getFirstObject(); let album: photoAccessHelper.Album = await fetchResult.getFirstObject();
console.info('get video Album successfully, albumUri: ' + album.albumUri); console.info('get video Album successfully, albumUri: ' + album.albumUri);
fetchResult.close(); fetchResult.close();
} catch (err) { } catch (err) {
...@@ -212,16 +219,17 @@ Example: Obtain a video in **Videos**. ...@@ -212,16 +219,17 @@ Example: Obtain a video in **Videos**.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions = { let fetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
try { try {
let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.VIDEO); let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.VIDEO);
let album = await albumFetchResult.getFirstObject(); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
console.info('get video Album successfully, albumUri: ' + album.albumUri); console.info('get video Album successfully, albumUri: ' + album.albumUri);
let videoFetchResult = await album.getAssets(fetchOptions); let videoFetchResult = await album.getAssets(fetchOptions);
...@@ -253,9 +261,11 @@ Use [getAlbums](../reference/apis/js-apis-photoAccessHelper.md#getalbums) to obt ...@@ -253,9 +261,11 @@ Use [getAlbums](../reference/apis/js-apis-photoAccessHelper.md#getalbums) to obt
2. Use **getAlbums** to obtain a screenshot album object. 2. Use **getAlbums** to obtain a screenshot album object.
```ts ```ts
import photoAccessHelper from '@ohos.file.photoAccessHelper';
try { try {
let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.SCREENSHOT); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.SCREENSHOT);
let album = await fetchResult.getFirstObject(); let album: photoAccessHelper.Album = await fetchResult.getFirstObject();
console.info('get screenshot Album successfully, albumUri: ' + album.albumUri); console.info('get screenshot Album successfully, albumUri: ' + album.albumUri);
fetchResult.close(); fetchResult.close();
} catch (err) { } catch (err) {
...@@ -283,16 +293,17 @@ Example: Obtain a media asset from **Screenshots**. ...@@ -283,16 +293,17 @@ Example: Obtain a media asset from **Screenshots**.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions = { let fetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
try { try {
let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.SCREENSHOT); let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.SCREENSHOT);
let album = await albumFetchResult.getFirstObject(); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
console.info('get screenshot album successfully, albumUri: ' + album.albumUri); console.info('get screenshot album successfully, albumUri: ' + album.albumUri);
let screenshotFetchResult = await album.getAssets(fetchOptions); let screenshotFetchResult = await album.getAssets(fetchOptions);
......
...@@ -34,9 +34,11 @@ Example: Create a user album. ...@@ -34,9 +34,11 @@ Example: Create a user album.
2. Use **createAlbum** to create an album. 2. Use **createAlbum** to create an album.
```ts ```ts
import photoAccessHelper from '@ohos.file.photoAccessHelper';
try { try {
let albumName = 'albumName'; let albumName: photoAccessHelper.AlbumName = 'albumName';
let album = await phAccessHelper.createAlbum(albumName); let album: photoAccessHelper.Album = await phAccessHelper.createAlbum(albumName);
console.info('createAlbum successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri); console.info('createAlbum successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri);
} catch (err) { } catch (err) {
console.error('createAlbum failed with err: ' + err); console.error('createAlbum failed with err: ' + err);
...@@ -62,18 +64,19 @@ Example: Obtain the user album named **albumName**. ...@@ -62,18 +64,19 @@ Example: Obtain the user album named **albumName**.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME; let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME;
predicates.equalTo(albumName, 'albumName'); predicates.equalTo(albumName, 'albumName');
let fetchOptions = { let fetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
try { try {
let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions);
let album = await fetchResult.getFirstObject(); let album: photoAccessHelper.Album = await fetchResult.getFirstObject();
console.info('getAlbums successfully, albumName: ' + album.albumName); console.info('getAlbums successfully, albumName: ' + album.albumName);
fetchResult.close(); fetchResult.close();
} catch (err) { } catch (err) {
...@@ -106,18 +109,19 @@ Example: Rename an album named **albumName**. ...@@ -106,18 +109,19 @@ Example: Rename an album named **albumName**.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME; let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME;
predicates.equalTo(albumName, 'albumName'); predicates.equalTo(albumName, 'albumName');
let fetchOptions = { let fetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
try { try {
let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions);
let album = await fetchResult.getFirstObject(); let album: photoAccessHelper.Album = await fetchResult.getFirstObject();
console.info('getAlbums successfully, albumName: ' + album.albumName); console.info('getAlbums successfully, albumName: ' + album.albumName);
album.albumName = 'newAlbumName'; album.albumName = 'newAlbumName';
await album.commitModify(); await album.commitModify();
...@@ -150,24 +154,25 @@ Example: Add an image to the album **albumName**. ...@@ -150,24 +154,25 @@ Example: Add an image to the album **albumName**.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let albumPredicates = new dataSharePredicates.DataSharePredicates(); let albumPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME; let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME;
albumPredicates.equalTo(albumName, 'albumName'); albumPredicates.equalTo(albumName, 'albumName');
let albumFetchOptions = { let albumFetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: albumPredicates predicates: albumPredicates
}; };
let photoPredicates = new dataSharePredicates.DataSharePredicates(); let photoPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let photoFetchOptions = { let photoFetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: photoPredicates predicates: photoPredicates
}; };
try { try {
let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
let album = await albumFetchResult.getFirstObject(); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
console.info('getAlbums successfully, albumName: ' + album.albumName); console.info('getAlbums successfully, albumName: ' + album.albumName);
let photoFetchResult = await phAccessHelper.getAssets(photoFetchOptions); let photoFetchResult = await phAccessHelper.getAssets(photoFetchOptions);
let fileAsset = await photoFetchResult.getFirstObject(); let fileAsset = await photoFetchResult.getFirstObject();
...@@ -202,24 +207,25 @@ Example: Obtain an image in the user album **albumName**. ...@@ -202,24 +207,25 @@ Example: Obtain an image in the user album **albumName**.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let albumPredicates = new dataSharePredicates.DataSharePredicates(); let albumPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME; let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME;
albumPredicates.equalTo(albumName, 'albumName'); albumPredicates.equalTo(albumName, 'albumName');
let albumFetchOptions = { let albumFetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: albumPredicates predicates: albumPredicates
}; };
let photoPredicates = new dataSharePredicates.DataSharePredicates(); let photoPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let photoFetchOptions = { let photoFetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: photoPredicates predicates: photoPredicates
}; };
try { try {
let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
let album = await albumFetchResult.getFirstObject(); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
console.info('getAlbums successfully, albumName: ' + album.albumName); console.info('getAlbums successfully, albumName: ' + album.albumName);
let photoFetchResult = await album.getAssets(photoFetchOptions); let photoFetchResult = await album.getAssets(photoFetchOptions);
let fileAsset = await photoFetchResult.getFirstObject(); let fileAsset = await photoFetchResult.getFirstObject();
...@@ -256,24 +262,25 @@ Example: Remove an image from the album named **albumName**. ...@@ -256,24 +262,25 @@ Example: Remove an image from the album named **albumName**.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let albumPredicates = new dataSharePredicates.DataSharePredicates(); let albumPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME; let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME;
albumPredicates.equalTo(albumName, 'albumName'); albumPredicates.equalTo(albumName, 'albumName');
let albumFetchOptions = { let albumFetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: albumPredicates predicates: albumPredicates
}; };
let photoPredicates = new dataSharePredicates.DataSharePredicates(); let photoPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let photoFetchOptions = { let photoFetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: photoPredicates predicates: photoPredicates
}; };
try { try {
let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
let album = await albumFetchResult.getFirstObject(); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
console.info('getAlbums successfully, albumName: ' + album.albumName); console.info('getAlbums successfully, albumName: ' + album.albumName);
let photoFetchResult = await album.getAssets(photoFetchOptions); let photoFetchResult = await album.getAssets(photoFetchOptions);
let fileAsset = await photoFetchResult.getFirstObject(); let fileAsset = await photoFetchResult.getFirstObject();
...@@ -306,18 +313,19 @@ Example: Delete a user album named **albumName**. ...@@ -306,18 +313,19 @@ Example: Delete a user album named **albumName**.
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME; let albumName: photoAccessHelper.AlbumName = photoAccessHelper.AlbumKey.ALBUM_NAME;
predicates.equalTo(albumName, '%albumName%'); predicates.equalTo(albumName, '%albumName%');
let fetchOptions = { let fetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
try { try {
let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions);
let album = await fetchResult.getFirstObject(); let album: photoAccessHelper.Album = await fetchResult.getFirstObject();
console.info('getAlbums successfully, albumName: ' + album.albumName); console.info('getAlbums successfully, albumName: ' + album.albumName);
phAccessHelper.deleteAlbums([album]); phAccessHelper.deleteAlbums([album]);
fetchResult.close(); fetchResult.close();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册