HarmonyOS如何代码实现打开相机应用

HarmonyOS如何代码实现打开相机应用

HarmonyOS
2024-08-12 15:18:33
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa

可参考如下代码:

import common from '@ohos.app.ability.common'; 
import Want from '@ohos.app.ability.Want'; 
function startImageCapture(context: common.UIAbilityContext): void { 
  let want: Want = { 
    action: 'ohos.want.action.imageCapture', 
    parameters: { 
      callBundleName: 'com.example.myapplication', 
      supportMultiMode: false 
    } 
  }; 
  context.startAbilityForResult(want, (err, data) => { 
    if (err.code) { 
      console.error(`Failed to start ability for result. Code is ${err.code}, message is ${err.message}`); 
      return; 
    } 
    console.info(`Succeeded in starting ability for result. Data is ${JSON.stringify(data)}`); 
  }) 
} 
function startVideoCapture(context: common.UIAbilityContext): void { 
  let want: Want = { 
    action: 'ohos.want.action.videoCapture', 
    parameters: { 
      callBundleName: 'com.example.myapplication', 
      supportMultiMode: false 
    } 
  }; 
  context.startAbilityForResult(want, (err, data) => { 
    if (err.code) { 
      console.error(`Failed to start ability for result. Code is ${err.code}, message is ${err.message}`); 
      return; 
    } 
    console.info(`Succeeded in starting ability for result. Data is ${JSON.stringify(data)}`); 
  }) 
} 
@Entry 
@Component 
struct Index { 
  build() { 
    Row() { 
      Column() { 
        Button('Start Camera', { stateEffect: true, type: ButtonType.Capsule }) 
          .width('80%') 
          .height(40) 
          .margin(10) 
          .onClick(() => { 
            const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; 
            startImageCapture(context); // 打开相机拍照 
          }) 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}
分享
微博
QQ
微信
回复
2024-08-13 12:04:31
相关问题
打开相机:直接使用相机拍照能力
1612浏览 • 1回复 待解决
HarmonyOS APP无法打开相机拍照
449浏览 • 1回复 待解决
HarmonyOS 如何打开应用
226浏览 • 2回复 待解决
HarmonyOS 相机打开闪光灯设置无效
1018浏览 • 1回复 待解决
HarmonyOS 应用相机开发疑问
183浏览 • 1回复 待解决
HarmonyOS如何实现相机手动对焦
415浏览 • 1回复 待解决
HarmonyOS如何打开外部地图应用
557浏览 • 1回复 待解决
HarmonyOS 应用打开pdf
322浏览 • 1回复 待解决
HarmonyOS H5拉起系统相机的样例代码
259浏览 • 1回复 待解决
如何简单实现相机关闭
545浏览 • 1回复 待解决
HarmonyOS有没有打开系统设置页的代码
330浏览 • 1回复 待解决
分布式相机功能在应用层怎么实现
3251浏览 • 1回复 待解决