JSUI如何选择图片
JSUI有没有类似input type=file的图片选择,或者Java等其他实现也可以。
解决办法:使用@ohos.multimedia.medialibrary 媒体数据管理接口
参考api:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-medialibrary-0000001168747257#section393611281845
let option = { type : "image", count : 2 }; mediaLibrary.getMediaLibrary().startMediaSelect(option).then((value) => { console.log("Media resources selected."+value); // Obtain the media selection value. }).catch((err) => { console.log("An error occurred when selecting media resources."); });还有其他三种方法,但是都行不通:
- 在文件交互,使用document.show可以实现选择文件,但是返回报错,模拟器可以实现,具体错误在:https://developer.huawei.com/consumer/cn/forum/topic/0201746480559100500?fid=0102683795438680754
具体api参考:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-document-0000001168936589
-
使用featureAbility.startAbility,但是没有返回值
var str = { "want": { "deviceId": "", "bundleName": "", "abilityName": "", "uri": "", "type": "image/*", "options": {}, "action": wantConstant.Action.ACTION_CHOOSE, "parameters": {}, "entities": [ wantConstant.Entity.ENTITY_DEFAULT ], "flags":wantConstant.Flags.FLAG_ABILITY_FORWARD_RESULT }, "abilityStartSetting": {} }; featureAbility.startAbility(str, (err, data) => { if (err) { console.error('Operation failed. Cause:' + JSON.stringify(err)); return; } console.info('Operation successful. Data: ' + JSON.stringify(data)) }); -
使用调用Java的代码,也是没有返回值
Intent intent = new Intent(); Operation opt=new Intent.OperationBuilder().withAction("android.intent.action.GET_CONTENT").build(); intent.setOperation(opt); intent.addFlags(Intent.FLAG_NOT_OHOS_COMPONENT); intent.setType("image/*"); startAbilityForResult(intent, imgRequestCode);请问还有其他实现方式吗?
8
浏览519 编辑于2021-12-13 09:55未知归属地
全部评论
最多点赞
最新发布
最早发布
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
- 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
- 如您发布的内容为转载内容,请注明内容来源。
我要发帖子
了解社区公约,与您携手共创和谐专业的开发者社区。










































苏公安网备 32011402010933号