HarmonyOS 升级后DataSharePredicates.or没有了,DataSharePredicates.in查询uri时抛了异常

升级后的操作系统版本2.1.3.5,   Preview(2.0.0.33)-SP35C00E33R4P11log

异常信息:medialibrary inner fail,code=14000011

问题代码:

const photoPicker = new photoAccessHelper.PhotoViewPicker(); 
const result = await photoPicker.select(); 
const uris = result.photoUris; 
const predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 
predicates.in(photoAccessHelper.PhotoKeys.URI, uris) 
const fetchOption: photoAccessHelper.FetchOptions = { 
  fetchColumns: [], 
  predicates: predicates 
}; 
const phInstance = photoAccessHelper.getPhotoAccessHelper(getContext()); 
const fetchResult = await phInstance.getAssets(fetchOption);

通过Asset查询媒体信息。


HarmonyOS
6天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Heiang

可以用这种方式可以获取,非批量获取,picker的方式并非必须同时全部获取到,逐个获取同样可以满足大多场景,参考代码如下:

async function getUri() { 
  console.info("NLZNLZ getUri enter"); 
  const photoPicker = new photoAccessHelper.PhotoViewPicker(); 
  const result = await photoPicker.select(); 
 
  const uris = result.photoUris; 
 
  uris.forEach((uri, index) => { 
    const predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 
    predicates.equalTo(photoAccessHelper.PhotoKeys.URI, uri.toString()) 
 
    predicates.equalTo(photoAccessHelper.PhotoKeys.URI, uri) 
    const fetchOption: photoAccessHelper.FetchOptions = { 
      fetchColumns: [photoAccessHelper.PhotoKeys.WIDTH, photoAccessHelper.PhotoKeys.HEIGHT, photoAccessHelper.PhotoKeys.SIZE], 
      predicates: predicates 
    }; 
    const phInstance = photoAccessHelper.getPhotoAccessHelper(getContext()); 
    phInstance.getAssets(fetchOption, async (err, fetchResult) => { 
      if (fetchResult !== undefined) { 
        let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject() 
        if (photoAsset !== undefined) { 
          console.info("NLZNLZ filename: " + photoAsset.displayName + 
            ", width: " + photoAsset.get(photoAccessHelper.PhotoKeys.WIDTH.toString()) + 
            ", height" + photoAsset.get(photoAccessHelper.PhotoKeys.HEIGHT.toString()) + 
            ", size: " + photoAsset.get(photoAccessHelper.PhotoKeys.SIZE.toString())) 
        } 
      } else { 
        console.error("NLZNLZ fetch result fail " + err) 
      } 
    }) 
  }) 
  // const fetchResult = await phInstance.getAssets(fetchOption) 
  console.log("NLZNLZ 11111111111111111") 
}
分享
微博
QQ
微信
回复
6天前
相关问题
升级系统之后,原来安装的app没有
102浏览 • 1回复 待解决
系统日历方法使用会异常
338浏览 • 0回复 待解决
荣耀8x何时升级鸿蒙
6885浏览 • 2回复 待解决
HarmonyOS svg图片运行颜色变色
137浏览 • 1回复 待解决
鸿蒙系统异构组网到底实现没有?
8271浏览 • 1回复 待解决
对openHarmony应用进行签名失败
9222浏览 • 3回复 已解决
Ctex编译成功但是没有pdf生成
3735浏览 • 0回复 待解决