
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源
去关联
在卡片开发过程中,采用文档的方法显示图片到JS卡片上一直失败,下方是相关代码:
private void UpdataFormIma(){
HiLog.info(TAG, "更新卡片图片");
try{
//定义数据能力帮助对象
DataAbilityHelper helper = DataAbilityHelper.creator(getContext());
FileInputStream inputStream = null;
inputStream = new FileInputStream(helper.openFile(uri, "r"));
byte[] bytes = readInputStream(inputStream);
ZSONObject result = new ZSONObject();
FormBindingData formBindingData = new FormBindingData(result);
if (bytes != null && bytes.length != 0) {
String picName = new Date().getTime() + ".png";
String picPath = "memory://" + picName;
assert result != null;
result.put("avatarIma", picPath);
formBindingData.addImageData(picName, bytes);
}
if (this instanceof Ability) {
for (CardDataTable formtable : getFormId()) {
updateForm(formtable.getFormId(), formBindingData);
}
}
}catch (Exception e){
HiLog.error(TAG,"不存在");
}
}
之后在一篇文章上看到,卡片刷新图片的方式是回到桌面才进行刷新,所以我在页面的onStop()和onTonInactive()方法上调用卡片刷新的代码,这样将图片显示到桌面卡片上。