获取HarmonyOS 鸿蒙Next相册数据失败 Error: System inner fail
获取HarmonyOS 鸿蒙Next相册数据失败 Error: System inner fail
打开了图片与视频权限,调用了savebutton,但还是无法正常获取到相册数据(此逻辑直接用的官方文档代码)。
SaveButton()
.onClick((event, result: SaveButtonOnClickResult) => {
if (result === SaveButtonOnClickResult.SUCCESS) {
example()
}
})
.width(200)
.height(80)
let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(getContext());
async function example() {
try {
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let albumName: photoAccessHelper.AlbumKeys = photoAccessHelper.AlbumKeys.ALBUM_NAME;
predicates.equalTo(albumName, ‘album_name’);
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
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) {
console.error('getAlbums failed with err: ’ + err);
}
}
5 回复
好的,感谢!申请方法的链接暂时无权限查看,后续放开后尝试看看。
我的问题和他类似但是“ohos.permission.READ_IMAGEVIDEO”已经在ACL申请了,目前是想实现获取相册或者图片,然后添加对他们的监听,但是在调用phAccessHelper.getAssets()接口获取图片资源时,报错“hrowError errCode:201 errMsg:Permission denied”,接口调用前设备上已用户授权了。求大神指点。