中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
在卡片开发过程中,采用文档的方法显示图片到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()方法上调用卡片刷新的代码,这样将图片显示到桌面卡片上。
微信扫码分享