HarmonyOS 系统的ArkUI中的WebView组件,能不能直接使用input标签直接调起相机?

HarmonyOS 系统的ArkUI中的WebView组件,能不能直接使用input标签直接调起相机?


HarmonyOS
2024-11-07 11:00:40
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

没有手动去调用启动相机的ability,H5调用相机需要写代码去拉起,示例代码见下方。

import webview from '@ohos.web.webview'; 
import { BusinessError } from '@ohos.base'; 
import common from '@ohos.app.ability.common'; 
 
@Entry 
@Component 
struct Index { 
  @State message: string = 'Hello World'; 
  controller = new webview.WebviewController(); 
 
 
  invokeCamera(callback?: (uri: string) => void) { 
    const context = getContext(this) as common.UIAbilityContext 
    context.startAbilityForResult({ 
      action: 'ohos.want.action.imageCapture', 
      parameters: { 
        callBundleName: 'com.example.mydemo' 
      } 
    }, (err: BusinessError, data: common.AbilityResult) => { 
      if (err && err.code != 0) { 
        console.error('imageCapture error:' + ${JSON.stringify(err)}); 
        return; 
      } 
      console.warn('imageCapture data:' + ${JSON.stringify(data)} 
 
 
      ) 
      ; 
      let uri = data?.want?.parameters?.resourceUri; 
      if (callback && uri) { 
        callback(uri.toString()) 
        ; 
      } 
    }) 
 
  } 
 
 
  build() { 
    Row() { 
      Column() { 
        Web({ src: $rawfile('index.html'), controller: this.controller }) 
          .onShowFileSelector((event) => { 
            if (!event) { 
              return false; 
            } 
            console.log('isCapture: ' + event.fileSelector.isCapture()) 
            this.invokeCamera(uri => { 
              event?.result.handleFileList([uri]); 
            }); 
            return true; 
          }) 
 
 
      } 
      .width('100%') 
    } 
    .height('100%') 
 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
分享
微博
QQ
微信
回复
2024-11-07 17:17:28
相关问题
HarmonyOS input标签怎么调起系统相册
842浏览 • 1回复 待解决
电脑能不能刷鸿蒙系统
17289浏览 • 14回复 待解决
升级鸿蒙系统后原来app能不能
11999浏览 • 2回复 待解决
打开相机:直接使用相机拍照能力
2629浏览 • 1回复 待解决
荣耀30pro能不能升级鸿蒙系统
8263浏览 • 1回复 待解决
荣耀30S能不能升级鸿蒙系统
10094浏览 • 1回复 待解决
@State能不能装饰接口
1491浏览 • 1回复 待解决
HarmonyOS 如何直接调起拨打电话
1112浏览 • 1回复 待解决
鸿蒙可以直接调用系统相机吗?
9540浏览 • 1回复 待解决
opporeno5pro能不能装鸿蒙系统
10739浏览 • 1回复 待解决
HarmonyOS Camera_CaptureSession 能不能重用
1057浏览 • 1回复 待解决
File公有目录是不能不能创建 ?
3498浏览 • 1回复 待解决
华为能不能做个快捷指令?
8448浏览 • 1回复 待解决
DevEco Studio 不能直接更新?
10207浏览 • 8回复 已解决