未验证 提交 2fd23187 编写于 作者: O openharmony_ci 提交者: Gitee

!23416 示例代码编译告警修复跳单 monthly_20230815

Merge pull request !23416 from 胡伟奇/cherry-pick-1693303741
...@@ -1315,37 +1315,36 @@ getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions, callbac ...@@ -1315,37 +1315,36 @@ getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions, callbac
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() { async function example() {
console.info('getPhotoIndexDemo'); try {
let predicatesForGetAsset = new dataSharePredicates.DataSharePredicates(); console.info('getPhotoIndexDemo');
let fetchOp = { let predicatesForGetAsset = new dataSharePredicates.DataSharePredicates();
fetchColumns: [], let fetchOp = {
predicates: predicatesForGetAsset fetchColumns: [],
}; predicates: predicatesForGetAsset
//Obtain the uri of the album };
let albumFetchResult = await helper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp); // Obtain the uri of the album
let album = await albumFetchResult.getFirstObject(); let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp);
let album = await albumFetchResult.getFirstObject();
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates = new dataSharePredicates.DataSharePredicates();
predicates.orderByAsc("add_modified"); predicates.orderByAsc(photoAccessHelper.PhotoKeys.DATE_MODIFIED);
let fetchOptions = { let fetchOptions = {
fetchColumns: [], fetchColumns: [photoAccessHelper.PhotoKeys.DATE_MODIFIED],
predicates: predicates predicates: predicates
}; };
let photoFetchResult = await album.getAssets(fetchOptions); let photoFetchResult = await album.getAssets(fetchOptions);
let expectIndex = 1; let expectIndex = 1;
//Obtain the uri of the second file // Obtain the uri of the second file
let photoAsset = await photoFetchResult.getObjectByPosition(expectIndex); let photoAsset = await photoFetchResult.getObjectByPosition(expectIndex);
photoAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions, (err, index) => { phAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions, (err, index) => {
try {
if (err == undefined) { if (err == undefined) {
console.info(`getPhotoIndex successfully and index is : ${index}`); console.info(`getPhotoIndex successfully and index is : ${index}`);
} else { } else {
console.info(`getPhotoIndex failed;`); console.info(`getPhotoIndex failed;`);
} }
} catch (error) { });
console.info(`getPhotoIndex failed; error: ${error}`); } catch (error) {
} console.info(`getPhotoIndex failed; error: ${error}`);
} }
} }
``` ```
...@@ -1390,33 +1389,34 @@ getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promis ...@@ -1390,33 +1389,34 @@ getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promis
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() { async function example() {
console.info('getPhotoIndexDemo'); try {
let predicatesForGetAsset = new dataSharePredicates.DataSharePredicates(); console.info('getPhotoIndexDemo');
let fetchOp = { let predicatesForGetAsset = new dataSharePredicates.DataSharePredicates();
fetchColumns: [], let fetchOp = {
predicates: predicatesForGetAsset fetchColumns: [],
}; predicates: predicatesForGetAsset
//Obtain the uri of the album };
let albumFetchResult = await helper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp); // Obtain the uri of the album
let album = await albumFetchResult.getFirstObject(); let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp);
let album = await albumFetchResult.getFirstObject();
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates = new dataSharePredicates.DataSharePredicates();
predicates.orderByAsc("add_modified"); predicates.orderByAsc(photoAccessHelper.PhotoKeys.DATE_MODIFIED);
let fetchOptions = { let fetchOptions = {
fetchColumns: [], fetchColumns: [photoAccessHelper.PhotoKeys.DATE_MODIFIED],
predicates: predicates predicates: predicates
}; };
let photoFetchResult = await album.getAssets(fetchOptions); let photoFetchResult = await album.getAssets(fetchOptions);
let expectIndex = 1; let expectIndex = 1;
//Obtain the uri of the second file // Obtain the uri of the second file
let photoAsset = await photoFetchResult.getObjectByPosition(expectIndex); let photoAsset = await photoFetchResult.getObjectByPosition(expectIndex);
phAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions).then((index) => {
photoAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions) console.info(`getPhotoIndex successfully and index is : ${index}`);
.then((index) => { }).catch((err) => {
console.info(`getPhotoIndex successfully and index is : ${index}`);
}).catch((err) => {
console.info(`getPhotoIndex failed; error: ${err}`); console.info(`getPhotoIndex failed; error: ${err}`);
}) });
} catch (error) {
console.info(`getPhotoIndex failed; error: ${error}`);
}
} }
``` ```
...@@ -2394,7 +2394,7 @@ getExif(): Promise<string> ...@@ -2394,7 +2394,7 @@ getExif(): Promise<string>
返回jpg格式图片Exif标签组成的json格式的字符串,该方法使用Promise方式返回结果。 返回jpg格式图片Exif标签组成的json格式的字符串,该方法使用Promise方式返回结果。
**注意**:此接口返回的是exif标签组成的json格式的字符串,完整exif信息由all_exif与photoKeys.USER_COMMENT组成,fetchColumns需要传入这两个字段。 **注意**:此接口返回的是exif标签组成的json格式的字符串,完整exif信息由all_exif与PhotoKeys.USER_COMMENT组成,fetchColumns需要传入这两个字段。
**系统接口**:此接口为系统接口。 **系统接口**:此接口为系统接口。
...@@ -2459,15 +2459,18 @@ async function example() { ...@@ -2459,15 +2459,18 @@ async function example() {
try { try {
console.info('getExifDemo'); console.info('getExifDemo');
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates = new dataSharePredicates.DataSharePredicates();
predicates.isNotNull('all_exif')
let fetchOptions = { let fetchOptions = {
fetchColumns: [ 'all_exif', photoKeys.USER_COMMENT], fetchColumns: ['all_exif', photoAccessHelper.PhotoKeys.USER_COMMENT],
predicates: predicates predicates: predicates
}; };
let fetchResult = await phAccessHelper.getAssets(fetchOptions); let fetchResult = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject(); let fileAsset = await fetchResult.getFirstObject();
console.info('getExifDemo fileAsset displayName: ' + JSON.stringify(fileAsset.displayName));
let exifMessage = await fileAsset.getExif(); let exifMessage = await fileAsset.getExif();
let userCommentKey = 'UserComment'; let userCommentKey = 'UserComment';
let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]);
console.info('getExifDemo userComment: ' + JSON.stringify(userComment));
fetchResult.close(); fetchResult.close();
} catch (err) { } catch (err) {
console.error('getExifDemoCallback failed with error: ' + err); console.error('getExifDemoCallback failed with error: ' + err);
...@@ -2481,7 +2484,7 @@ getExif(callback: AsyncCallback<string>): void ...@@ -2481,7 +2484,7 @@ getExif(callback: AsyncCallback<string>): void
返回jpg格式图片Exif标签组成的json格式的字符串,该方法使用Promise方式返回结果。 返回jpg格式图片Exif标签组成的json格式的字符串,该方法使用Promise方式返回结果。
**注意**:此接口返回的是exif标签组成的json格式的字符串,完整exif信息由all_exif与photoKeys.USER_COMMENT组成,fetchColumns需要传入这两个字段。 **注意**:此接口返回的是exif标签组成的json格式的字符串,完整exif信息由all_exif与PhotoKeys.USER_COMMENT组成,fetchColumns需要传入这两个字段。
**系统接口**:此接口为系统接口。 **系统接口**:此接口为系统接口。
...@@ -2546,16 +2549,19 @@ async function example() { ...@@ -2546,16 +2549,19 @@ async function example() {
try { try {
console.info('getExifDemo'); console.info('getExifDemo');
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates = new dataSharePredicates.DataSharePredicates();
predicates.isNotNull('all_exif')
let fetchOptions = { let fetchOptions = {
fetchColumns: [ 'all_exif', photoKeys.USER_COMMENT], fetchColumns: ['all_exif', photoAccessHelper.PhotoKeys.USER_COMMENT],
predicates: predicates predicates: predicates
}; };
let fetchResult = await phAccessHelper.getAssets(fetchOptions); let fetchResult = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject(); let fileAsset = await fetchResult.getFirstObject();
console.info('getExifDemo fileAsset displayName: ' + JSON.stringify(fileAsset.displayName));
let userCommentKey = 'UserComment'; let userCommentKey = 'UserComment';
fileAsset.getExif((err, exifMessage) => { fileAsset.getExif((err, exifMessage) => {
if (exifMessage != undefined) { if (exifMessage != undefined) {
let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]);
console.info('getExifDemo userComment: ' + JSON.stringify(userComment));
} else { } else {
console.error('getExif failed, message = ', err); console.error('getExif failed, message = ', err);
} }
......
...@@ -1433,37 +1433,35 @@ getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions, callbac ...@@ -1433,37 +1433,35 @@ getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions, callbac
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() { async function example() {
console.info('getPhotoIndexDemo'); try {
let predicatesForGetAsset = new dataSharePredicates.DataSharePredicates(); console.info('getPhotoIndexDemo');
let fetchOp = { let predicatesForGetAsset = new dataSharePredicates.DataSharePredicates();
fetchColumns: [], let fetchOp = {
predicates: predicatesForGetAsset fetchColumns: [],
}; predicates: predicatesForGetAsset
//Obtain the uri of the album };
let albumFetchResult = await mgr.getAlbums(userFileManager.AlbumType.SYSTEM, userFileManager.AlbumSubtype.FAVORITE, fetchOp); // Obtain the uri of the album
let album = await albumFetchResult.getFirstObject(); let albumFetchResult = await mgr.getAlbums(userFileManager.AlbumType.SYSTEM, userFileManager.AlbumSubType.FAVORITE, fetchOp);
let album = await albumFetchResult.getFirstObject();
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates = new dataSharePredicates.DataSharePredicates();
predicates.orderByAsc("add_modified"); predicates.orderByAsc(userFileManager.ImageVideoKey.DATE_MODIFIED);
let fetchOptions = { let fetchOptions = {
fetchColumns: [], fetchColumns: [userFileManager.ImageVideoKey.DATE_MODIFIED],
predicates: predicates predicates: predicates
}; };
let photoFetchResult = await album.getPhotoAssets(fetchOptions); let photoFetchResult = await album.getPhotoAssets(fetchOptions);
let expectIndex = 1; let expectIndex = 1;
//Obtain the uri of the second file // Obtain the uri of the second file
let photoAsset = await photoFetchResult.getPositionObject(expectIndex); let photoAsset = await photoFetchResult.getPositionObject(expectIndex);
mgr.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions, (err, index) => {
mgr.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions, (err, index) => {
try {
if (err == undefined) { if (err == undefined) {
console.info(`getPhotoIndex successfully and index is : ${index}`); console.info(`getPhotoIndex successfully and index is : ${index}`);
} else { } else {
console.info(`getPhotoIndex failed;`); console.info(`getPhotoIndex failed;`);
} }
} catch (error) { });
console.info(`getPhotoIndex failed; error: ${error}`); } catch (error) {
} console.info(`getPhotoIndex failed; error: ${error}`);
} }
} }
``` ```
...@@ -1508,33 +1506,34 @@ getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promis ...@@ -1508,33 +1506,34 @@ getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promis
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() { async function example() {
console.info('getPhotoIndexDemo'); try {
let predicatesForGetAsset = new dataSharePredicates.DataSharePredicates(); console.info('getPhotoIndexDemo');
let fetchOp = { let predicatesForGetAsset = new dataSharePredicates.DataSharePredicates();
fetchColumns: [], let fetchOp = {
predicates: predicatesForGetAsset fetchColumns: [],
}; predicates: predicatesForGetAsset
//Obtain the uri of the album };
let albumFetchResult = await mgr.getAlbums(userFileManager.AlbumType.SYSTEM, userFileManager.AlbumSubtype.FAVORITE, fetchOp); // Obtain the uri of the album
let album = await albumFetchResult.getFirstObject(); let albumFetchResult = await mgr.getAlbums(userFileManager.AlbumType.SYSTEM, userFileManager.AlbumSubType.FAVORITE, fetchOp);
let album = await albumFetchResult.getFirstObject();
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates = new dataSharePredicates.DataSharePredicates();
predicates.orderByAsc("add_modified"); predicates.orderByAsc(userFileManager.ImageVideoKey.DATE_MODIFIED);
let fetchOptions = { let fetchOptions = {
fetchColumns: [], fetchColumns: [userFileManager.ImageVideoKey.DATE_MODIFIED],
predicates: predicates predicates: predicates
}; };
let photoFetchResult = await album.getPhotoAssets(fetchOptions); let photoFetchResult = await album.getPhotoAssets(fetchOptions);
let expectIndex = 1; let expectIndex = 1;
//Obtain the uri of the second file // Obtain the uri of the second file
let photoAsset = await photoFetchResult.getPositionObject(expectIndex); let photoAsset = await photoFetchResult.getPositionObject(expectIndex);
mgr.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions).then((index) => {
mgr.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions) console.info(`getPhotoIndex successfully and index is : ${index}`);
.then((index) => { }).catch((err) => {
console.info(`getPhotoIndex successfully and index is : ${index}`);
}).catch((err) => {
console.info(`getPhotoIndex failed; error: ${err}`); console.info(`getPhotoIndex failed; error: ${err}`);
}) });
} catch (error) {
console.info(`getPhotoIndex failed; error: ${error}`);
}
} }
``` ```
...@@ -2566,15 +2565,18 @@ async function example() { ...@@ -2566,15 +2565,18 @@ async function example() {
try { try {
console.info('getExifDemo'); console.info('getExifDemo');
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates = new dataSharePredicates.DataSharePredicates();
predicates.isNotNull('all_exif')
let fetchOptions = { let fetchOptions = {
fetchColumns: [ 'all_exif', ImageVideoKey.USER_COMMENT], fetchColumns: ['all_exif', userFileManager.ImageVideoKey.USER_COMMENT],
predicates: predicates predicates: predicates
}; };
let fetchResult = await mgr.getPhotoAssets(fetchOptions); let fetchResult = await mgr.getPhotoAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject(); let fileAsset = await fetchResult.getFirstObject();
console.info('getExifDemo fileAsset displayName: ' + JSON.stringify(fileAsset.displayName));
let exifMessage = await fileAsset.getExif(); let exifMessage = await fileAsset.getExif();
let userCommentKey = 'UserComment'; let userCommentKey = 'UserComment';
let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]);
console.info('getExifDemo userComment: ' + JSON.stringify(userComment));
fetchResult.close(); fetchResult.close();
} catch (err) { } catch (err) {
console.error('getExifDemoCallback failed with error: ' + err); console.error('getExifDemoCallback failed with error: ' + err);
...@@ -2653,16 +2655,19 @@ async function example() { ...@@ -2653,16 +2655,19 @@ async function example() {
try { try {
console.info('getExifDemo'); console.info('getExifDemo');
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates = new dataSharePredicates.DataSharePredicates();
predicates.isNotNull('all_exif')
let fetchOptions = { let fetchOptions = {
fetchColumns: [ 'all_exif', ImageVideoKey.USER_COMMENT], fetchColumns: ['all_exif', userFileManager.ImageVideoKey.USER_COMMENT],
predicates: predicates predicates: predicates
}; };
let fetchResult = await mgr.getPhotoAssets(fetchOptions); let fetchResult = await mgr.getPhotoAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject(); let fileAsset = await fetchResult.getFirstObject();
console.info('getExifDemo fileAsset displayName: ' + JSON.stringify(fileAsset.displayName));
let userCommentKey = 'UserComment'; let userCommentKey = 'UserComment';
fileAsset.getExif((err, exifMessage) => { fileAsset.getExif((err, exifMessage) => {
if (exifMessage != undefined) { if (exifMessage != undefined) {
let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]);
console.info('getExifDemo userComment: ' + JSON.stringify(userComment));
} else { } else {
console.error('getExif failed, message = ', err); console.error('getExif failed, message = ', err);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册