赞
踩
版本:Api9,Stage模型
- import mediaLibrary from '@ohos.multimedia.mediaLibrary';
- import Ability from '@ohos.application.Ability';
- import AbilityStage from "@ohos.application.AbilityStage";
- import context from '@ohos.application.context';
- @Entry
- @Component
- struct Index {
- @State message: string = '选择单张图片'
- @State img: string = ''
- build() {
- Row() {
- Column() {
- Text(this.message)
- .fontSize(50)
- .fontWeight(FontWeight.Bold).onClick(()=>{
- let context = getContext(this) as any
- let startParmameter = {
- bundleName:"com.ohos.photos",
- abilityName: "com.ohos.photos.MainAbility",
- parameters: {
- uri: "singleselect"
- }
- };
- context.startAbilityForResult(startParmameter).then((result) => {
- console.info(`startAbilityForResult Promise.resolve is called, result.resultCode = ${JSON.stringify(result)}`)
- let want = result['want'];
- console.info(`test select single ${JSON.stringify(want)}`);
- if (want != null && want != undefined) {
- let param = want['parameters'];
- console.info(`test select single ${JSON.stringify(param)}`);
- if (param != null && param != undefined) {
- let uri = param['select-item-list'];
- this.img=param['select-item-list'];
- console.info(`图片路径是 ${uri}`);
- }
- }
- }, (error) => {
- console.info(`startAbilityForResult Promise.Reject is called, error.code = ${error.code}`)
- })
- })
- Image(this.img).width(50).height(50)
-
- .width('100%')
- }
- .height('100%')
- }
- }}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。