HarmonyOS H5拉起系统相机的样例代码

H5拉起系统相机的样例代码。

HarmonyOS
2024-10-28 10:39:10
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

【local.html】

<!DOCTYPE html>  
<html>  
<body>  
<button type="button" onclick="cameraImage()">唤起照相机</button>  
<p id="demo"></p>  
<script>  
    function cameraImage(){  
    let str2=cameraImageName.testCameraImage();  
    }  
</script>  
</body>  
</html>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.

【index.ets】

import common from '@ohos.app.ability.common';  
import web_webview from '@ohos.web.webview';  
  
class cameraImage {  
  constructor() {  
  }  
  
  testCameraImage(): string {  
    const context = getContext(this) as common.UIAbilityContext  
    context.startAbilityForResult({  
      action:"ohos.want.action.imageCapture",  
      parameters:{  
        callBundleName:"com.hm.imageshow"  
      }  
    },(err,data) => {  
      console.info("imageCapture:" + `${JSON.stringify(data)}`)  
    })  
    return '1221';  
  }  
  
}  
  
@Entry  
@Component  
struct camera{  
  controller: web_webview.WebviewController = new web_webview.WebviewController();  
  @State webCameraImage: cameraImage = new cameraImage();  
  
  aboutToAppear(){  
    // 配置Web开启调试模式  
    web_webview.WebviewController.setWebDebuggingAccess(true);  
  }  
  
  build() {  
    Column() {  
      Web({ src: $rawfile('local.html'), controller: this.controller })  
        .javaScriptAccess(true)  
        .javaScriptProxy({  
          object: this.webCameraImage,  
          name: "cameraImageName",  
          methodList: ["testCameraImage"],  
          controller: this.controller  
        })  
    }  
  }  
}
  • 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.
分享
微博
QQ
微信
回复
2024-10-28 16:03:52


相关问题
HarmonyOS h5调用系统相机进行拍照
502浏览 • 1回复 待解决
HarmonyOS h5拉起系统扫码页面的demo
800浏览 • 1回复 待解决
HarmonyOS web组件加载h5h5拉起摄像头
1220浏览 • 1回复 待解决
HarmonyOS h5拉起app,如何获取参数
431浏览 • 1回复 待解决
HarmonyOS H5代码如何复用?
893浏览 • 1回复 待解决
HarmonyOS H5打开原生相机
527浏览 • 1回复 待解决
HarmonyOS 应用并发同步代码
855浏览 • 1回复 待解决
H5通过url scheme拉起对应应用
1279浏览 • 1回复 待解决
HarmonyOS 请提供dsbridge代码
472浏览 • 1回复 待解决
HarmonyOS 直播功能指南与代码
601浏览 • 1回复 待解决
HarmonyOS 应用涉及H5代码,如何使用?
865浏览 • 1回复 待解决
HarmonyOS 外部H5页面,拉起手机银行app
541浏览 • 1回复 待解决
HarmonyOS 能否提供Web工程代码
686浏览 • 1回复 待解决
提问
该提问已有2人参与 ,帮助了13人