提交 02403b47 编写于 作者: N nwx1279094

文档告警修改

Signed-off-by: Nnwx1279094 <niuyuxin1@h-partners.com>

Change-Id: I8247378d2a0ea260c5e830b87cc966b98a882e71
上级 dad937c3
......@@ -81,7 +81,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME;
let albumName: photoAccessHelper.AlbumKeys = photoAccessHelper.AlbumKey.ALBUM_NAME;
predicates.equalTo(albumName, 'albumName');
let fetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [],
......
......@@ -108,7 +108,7 @@ The required permissions must be authorized by the user (user_grant). After addi
onWindowStageCreate(windowStage) {
let list : Array<Permissions> = ['ohos.permission.READ_IMAGEVIDEO', 'ohos.permission.WRITE_IMAGEVIDEO'];
let permissionRequestResult;
let atManager = abilityAccessCtrl.createAtManager();
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
atManager.requestPermissionsFromUser(this.context, list, (err, result) => {
if (err) {
console.error('requestPermissionsFromUserError: ' + JSON.stringify(err));
......
......@@ -99,8 +99,8 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
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 startTime: Number = 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: Number = 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 = photoAccessHelper.PhotoKeys.DATE_ADDED;
predicates.between(date_added, startTime, endTime);
predicates.orderByDesc(date_added); // Sort the obtained records in descending order.
......@@ -152,9 +152,10 @@ Example: Obtain the thumbnail of 720 x 720 of an image.
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
import image from '@ohos.multimedia.image';
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: dataSharePredicates.FetchOptions = {
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
......@@ -163,9 +164,9 @@ try {
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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);
let imageInfo = await pixelMap.getImageInfo()
let size: image.Size = { width: 720, height: 720 };
let pixelMap: image.PixelMap = await fileAsset.getThumbnail(size);
let imageInfo: image.ImageInfo = await pixelMap.getImageInfo()
console.info('getThumbnail successful, pixelMap ImageInfo size: ' + JSON.stringify(imageInfo.size));
fetchResult.close();
} catch (err) {
......@@ -195,12 +196,12 @@ Example: Create an image asset.
import photoAccessHelper from '@ohos.file.photoAccessHelper';
try {
let displayName = 'testPhoto' + Date.now() + '.jpg';
let displayName: string = 'testPhoto' + Date.now() + '.jpg';
let createOption: photoAccessHelper.CreateOptions = {
subType: photoAccessHelper.PhotoSubtype.DEFAULT
};
let fileAsset = await phAccessHelper.createAsset(displayName, createOption);
let fileAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(displayName, createOption);
console.info('createAsset successfully, file displayName: ' + fileAsset.displayName);
} catch (err) {
console.error('createAsset failed, message = ', err);
......@@ -235,7 +236,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: dataSharePredicates.FetchOptions = {
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: ['title'],
predicates: predicates
};
......@@ -280,7 +281,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: dataSharePredicates.FetchOptions = {
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
......
......@@ -62,16 +62,16 @@ Example: Favorite an image.
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(photoAccessHelper.ImageVideoKey.DISPLAY_NAME, 'test.jpg');
let fetchOptions: dataSharePredicates.FetchOptions = {
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
try {
let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await photoFetchResult.getFirstObject();
let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getFirstObject();
console.info('getAssets fileAsset.displayName : ' + fileAsset.displayName);
let favoriteState = true;
await fileAsset.setFavorite(favoriteState);
......@@ -102,8 +102,8 @@ Example: Obtain an image from **Favorites**.
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: dataSharePredicates.FetchOptions = {
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
......@@ -113,8 +113,8 @@ try {
let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
console.info('get favorite Album successfully, albumUri: ' + album.albumUri);
let photoFetchResult = await album.getAssets(fetchOptions);
let fileAsset = await photoFetchResult.getFirstObject();
let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getFirstObject();
console.info('favorite album getAssets successfully, albumName: ' + fileAsset.displayName);
photoFetchResult.close();
albumFetchResult.close();
......@@ -145,8 +145,8 @@ Example: Unfavorite an image.
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: dataSharePredicates.FetchOptions = {
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
......@@ -156,8 +156,8 @@ try {
let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
console.info('get favorite Album successfully, albumUri: ' + album.albumUri);
let photoFetchResult = await album.getAssets(fetchOptions);
let fileAsset = await photoFetchResult.getFirstObject();
let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getFirstObject();
console.info('favorite album getAssets successfully, albumName: ' + fileAsset.displayName);
let favoriteState = false;
await fileAsset.setFavorite(favoriteState);
......@@ -221,8 +221,8 @@ Example: Obtain a video in **Videos**.
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: dataSharePredicates.FetchOptions = {
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
......@@ -232,8 +232,8 @@ try {
let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
console.info('get video Album successfully, albumUri: ' + album.albumUri);
let videoFetchResult = await album.getAssets(fetchOptions);
let fileAsset = await videoFetchResult.getFirstObject();
let videoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await videoFetchResult.getFirstObject();
console.info('video album getAssets successfully, albumName: ' + fileAsset.displayName);
videoFetchResult.close();
albumFetchResult.close();
......@@ -295,8 +295,8 @@ Example: Obtain a media asset from **Screenshots**.
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: dataSharePredicates.FetchOptions = {
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
......@@ -306,8 +306,8 @@ try {
let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
console.info('get screenshot album successfully, albumUri: ' + album.albumUri);
let screenshotFetchResult = await album.getAssets(fetchOptions);
let fileAsset = await screenshotFetchResult.getFirstObject();
let screenshotFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await screenshotFetchResult.getFirstObject();
console.info('screenshot album getAssets successfully, albumName: ' + fileAsset.displayName);
screenshotFetchResult.close();
albumFetchResult.close();
......
......@@ -37,8 +37,8 @@ Example: Create a user album.
import photoAccessHelper from '@ohos.file.photoAccessHelper';
try {
let albumName: photoAccessHelper.AlbumName = 'albumName';
let album: photoAccessHelper.Album = await phAccessHelper.createAlbum(albumName);
let albumName = 'albumName';
let 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);
......@@ -66,10 +66,10 @@ Example: Obtain the user album named **albumName**.
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME;
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper.AlbumKeys = photoAccessHelper.AlbumKey.ALBUM_NAME;
predicates.equalTo(albumName, 'albumName');
let fetchOptions: dataSharePredicates.FetchOptions = {
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
......@@ -111,10 +111,10 @@ Example: Rename an album named **albumName**.
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME;
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper..AlbumKeys = photoAccessHelper.AlbumKey.ALBUM_NAME;
predicates.equalTo(albumName, 'albumName');
let fetchOptions: dataSharePredicates.FetchOptions = {
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
......@@ -156,16 +156,16 @@ Example: Add an image to the album **albumName**.
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let albumPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME;
let albumPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper..AlbumKeys = photoAccessHelper.AlbumKey.ALBUM_NAME;
albumPredicates.equalTo(albumName, 'albumName');
let albumFetchOptions: dataSharePredicates.FetchOptions = {
fetchColumns: [],
predicates: albumPredicates
};
let photoPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let photoFetchOptions: dataSharePredicates.FetchOptions = {
let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let photoFetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: photoPredicates
};
......@@ -174,8 +174,8 @@ try {
let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 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();
let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(photoFetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getFirstObject();
console.info('getAssets successfully, albumName: ' + fileAsset.displayName);
await album.addAssets([fileAsset]);
albumFetchResult.close();
......@@ -209,16 +209,16 @@ Example: Obtain an image in the user album **albumName**.
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let albumPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME;
let albumPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper.AlbumKeys = photoAccessHelper.AlbumKey.ALBUM_NAME;
albumPredicates.equalTo(albumName, 'albumName');
let albumFetchOptions: dataSharePredicates.FetchOptions = {
let albumFetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: albumPredicates
};
let photoPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let photoFetchOptions: dataSharePredicates.FetchOptions = {
let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let photoFetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: photoPredicates
};
......@@ -227,8 +227,8 @@ try {
let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 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();
let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(photoFetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getFirstObject();
console.info('album getAssets successfully, albumName: ' + fileAsset.displayName);
albumFetchResult.close();
photoFetchResult.close();
......@@ -264,16 +264,16 @@ Example: Remove an image from the album named **albumName**.
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let albumPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME;
let albumPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper.AlbumKeys = photoAccessHelper.AlbumKey.ALBUM_NAME;
albumPredicates.equalTo(albumName, 'albumName');
let albumFetchOptions: dataSharePredicates.FetchOptions = {
let albumFetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: albumPredicates
};
let photoPredicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let photoFetchOptions: dataSharePredicates.FetchOptions = {
let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let photoFetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: photoPredicates
};
......@@ -282,8 +282,8 @@ try {
let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 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();
let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(photoFetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getFirstObject();
console.info('album getAssets successfully, albumName: ' + fileAsset.displayName);
await album.removeAssets([fileAsset]);
albumFetchResult.close();
......@@ -315,10 +315,10 @@ Example: Delete a user album named **albumName**.
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates: dataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper.AlbumName = photoAccessHelper.AlbumKey.ALBUM_NAME;
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper.AlbumKeys = photoAccessHelper.AlbumKey.ALBUM_NAME;
predicates.equalTo(albumName, '%albumName%');
let fetchOptions: dataSharePredicates.FetchOptions = {
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
......
......@@ -33,20 +33,21 @@ photoAccessHelper提供监听媒体资源变更的接口,供开发者对指定
```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<photoAccessHelper.PhotoAsset> = 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 @@ try {
```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.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper.AlbumKeys = 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<photoAccessHelper.Album> = 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);
......@@ -127,21 +129,22 @@ try {
```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<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
console.info('getAssets fileAsset.uri : ' + fileAsset.uri);
await fileAsset.favorite(true);
fetchResult.close();
......@@ -169,23 +172,24 @@ try {
```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<photoAccessHelper.PhotoAsset> = 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);
......
......@@ -49,7 +49,7 @@ import photoAccessHelper from '@ohos.file.photoAccessHelper';
// 此处获取的phAccessHelper实例为全局对象,后续文档中使用到的地方默认为使用此处获取的对象,如未添加此段代码报未定义的错误请自行添加。
const context = getContext(this);
let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
let phAccessHelper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
```
## 申请相册管理模块功能相关权限
......@@ -108,7 +108,7 @@ let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
onWindowStageCreate(windowStage) {
let list : Array<Permissions> = ['ohos.permission.READ_IMAGEVIDEO', 'ohos.permission.WRITE_IMAGEVIDEO'];
let permissionRequestResult;
let atManager = abilityAccessCtrl.createAtManager();
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
atManager.requestPermissionsFromUser(this.context, list, (err, result) => {
if (err) {
console.error('requestPermissionsFromUserError: ' + JSON.stringify(err));
......
......@@ -33,10 +33,11 @@
```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 = {
调用PhotoAccessHelper.getAssets接口获取图片资源。
```ts
import photoAccessHelper from '@ohos.file.photoAccessHelper';
try {
let fetchResult = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject();
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 @@ try {
```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 = {
调用PhotoAccessHelper.getAssets接口获取图片资源。
```ts
import photoAccessHelper from '@ohos.file.photoAccessHelper';
try {
let fetchResult = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject();
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
console.info('getAssets fileAsset.uri : ' + fileAsset.uri);
fetchResult.close();
} catch (err) {
......@@ -90,15 +96,16 @@ try {
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let predicates = new dataSharePredicates.DataSharePredicates();
let startTime = Date.parse(new Date('2022-06-01').toString()) / 1000; // 查询起始时间距1970年1月1日的秒数值。
let endTime = Date.parse(new Date('2023-06-01').toString()) / 1000; // 查询结束时间距1970年1月1日的秒数值。
let date_added = photoAccessHelper.PhotoKeys.DATE_ADDED;
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let startTime: Number = 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: Number = 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 = photoAccessHelper.PhotoKeys.DATE_ADDED;
predicates.between(date_added, startTime, endTime);
predicates.orderByDesc(date_added); // 查询结果按照降序排序。
let fetchOptions = {
fetchColumns: [date_added], // date_added属性不属于默认查询列,需要自行添加。
predicates.orderByDesc(date_added); // Sort the obtained records in descending order.
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 = {
调用PhotoAccessHelper.getAssets接口获取图片资源。
```ts
import photoAccessHelper from '@ohos.file.photoAccessHelper';
try {
let fetchResult = await phAccessHelper.getAssets(fetchOptions);
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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,20 +151,22 @@ try {
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
import image from '@ohos.multimedia.image';
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<photoAccessHelper.PhotoAsset> = 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);
let imageInfo = await pixelMap.getImageInfo()
let size: image.Size = { width: 720, height: 720 };
let pixelMap: image.PixelMap = await fileAsset.getThumbnail(size);
let imageInfo: image.ImageInfo = await pixelMap.getImageInfo()
console.info('getThumbnail successful, pixelMap ImageInfo size: ' + JSON.stringify(imageInfo.size));
fetchResult.close();
} catch (err) {
......@@ -182,13 +193,15 @@ try {
2. 调用createAsset接口创建图片资源。
```ts
import photoAccessHelper from '@ohos.file.photoAccessHelper';
try {
let displayName = 'testPhoto' + Date.now() + '.jpg';
let createOption = {
let displayName: string = 'testPhoto' + Date.now() + '.jpg';
let createOption: photoAccessHelper.CreateOptions = {
subType: photoAccessHelper.PhotoSubtype.DEFAULT
};
let fileAsset = await phAccessHelper.createAsset(displayName, createOption);
let fileAsset: photoAccessHelper.photoAsset = await phAccessHelper.createAsset(displayName, createOption);
console.info('createAsset successfully, file displayName: ' + fileAsset.displayName);
} catch (err) {
console.error('createAsset failed, message = ', err);
......@@ -220,19 +233,20 @@ try {
```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: photoAccessHelper.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<photoAccessHelper.PhotoAsset> = 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 +278,17 @@ try {
```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: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
try {
let fetchResult = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject();
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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();
......
......@@ -29,9 +29,11 @@ photoAccessHelper仅提供开发者对收藏夹、视频相册、截屏和录屏
2. 调用getAlbums接口获取收藏夹对象。
```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<photoAccessHelper.Album> = 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,17 +60,18 @@ try {
```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 photoFetchResult = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await photoFetchResult.getFirstObject();
let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getFirstObject();
console.info('getAssets fileAsset.displayName : ' + fileAsset.displayName);
let favoriteState = true;
await fileAsset.setFavorite(favoriteState);
......@@ -97,20 +100,21 @@ try {
```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: photoAccessHelper.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<photoAccessHelper.Album> = 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);
let fileAsset = await photoFetchResult.getFirstObject();
let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getFirstObject();
console.info('favorite album getAssets successfully, albumName: ' + fileAsset.displayName);
photoFetchResult.close();
albumFetchResult.close();
......@@ -139,20 +143,21 @@ try {
```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: photoAccessHelper.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<photoAccessHelper.Album> = 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);
let fileAsset = await photoFetchResult.getFirstObject();
let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getFirstObject();
console.info('favorite album getAssets successfully, albumName: ' + fileAsset.displayName);
let favoriteState = false;
await fileAsset.setFavorite(favoriteState);
......@@ -182,9 +187,11 @@ try {
2. 调用getAlbums接口获取视频相册。
```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<photoAccessHelper.Album> = 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,20 +219,21 @@ try {
```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: photoAccessHelper.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<photoAccessHelper.Album> = 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);
let fileAsset = await videoFetchResult.getFirstObject();
let videoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await videoFetchResult.getFirstObject();
console.info('video album getAssets successfully, albumName: ' + fileAsset.displayName);
videoFetchResult.close();
albumFetchResult.close();
......@@ -253,9 +261,11 @@ try {
2. 调用getAlbums接口获取截屏和录屏相册。
```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<photoAccessHelper.Album> = 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,20 +293,21 @@ try {
```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: photoAccessHelper.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<photoAccessHelper.Album> = 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);
let fileAsset = await screenshotFetchResult.getFirstObject();
let screenshotFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions);
let fileAsset: photoAccessHelper.PhotoAsset = await screenshotFetchResult.getFirstObject();
console.info('screenshot album getAssets successfully, albumName: ' + fileAsset.displayName);
screenshotFetchResult.close();
albumFetchResult.close();
......
......@@ -34,9 +34,11 @@ photoAccessHelper提供用户相册相关的接口,供开发者创建、删除
2. 调用createAlbum接口创建相册。
```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 @@ try {
```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.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME;
predicates.equalTo(albumName, 'albumName');
let fetchOptions = {
let fetchOptions: photoAccessHelper.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<photoAccessHelper.Album> = 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) {
......@@ -108,18 +111,19 @@ try {
```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.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper = photoAccessHelper.AlbumKey.ALBUM_NAME;
predicates.equalTo(albumName, 'albumName');
let fetchOptions = {
let fetchOptions: photoAccessHelper.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<photoAccessHelper.Album> = 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();
......@@ -152,24 +156,25 @@ try {
```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.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.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let photoFetchOptions: photoAccessHelper.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<photoAccessHelper.Album> = 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();
......@@ -204,24 +209,25 @@ try {
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let albumPredicates = new dataSharePredicates.DataSharePredicates();
let albumPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME;
albumPredicates.equalTo(albumName, 'albumName');
let albumFetchOptions = {
let albumFetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: albumPredicates
};
let photoPredicates = new dataSharePredicates.DataSharePredicates();
let photoFetchOptions = {
let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let photoFetchOptions: photoAccessHelper.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<photoAccessHelper.Album> = 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();
......@@ -258,24 +264,25 @@ try {
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
let albumPredicates = new dataSharePredicates.DataSharePredicates();
let albumPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName = photoAccessHelper.AlbumKey.ALBUM_NAME;
albumPredicates.equalTo(albumName, 'albumName');
let albumFetchOptions = {
let albumFetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: albumPredicates
};
let photoPredicates = new dataSharePredicates.DataSharePredicates();
let photoFetchOptions = {
let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let photoFetchOptions: photoAccessHelper.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<photoAccessHelper.Album> = 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();
......@@ -308,18 +315,19 @@ try {
```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: photoAccessHelper.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<photoAccessHelper.Album> = 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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册