uni-app webview 嵌套h5时写的 <input type="file" capture="camera" />无法调用相机拍照

uni-app webview 嵌套h5时写的 <input type="file" capture="camera" />无法调用相机拍照

信息类别 内容
产品分类 uniapp/App
PC开发环境 Mac
版本号 macOS 15.2
HBuilderX Alpha
版本号 4.28
手机系统 全部
手机厂商 华为
页面类型 vue
vue版本 vue3
打包方式 云端
项目创建方式 HBuilderX

测试过的手机:

HarmonyOS 3.0.0

操作步骤:

  • webview 嵌套h5时写的 <input type="file" capture="camera" /> 无法调用相机拍照

预期结果:

  • webview 嵌套h5时写的 <input type="file" capture="camera" /> 可以正常调用相机拍照上传

实际结果:

  • webview 嵌套h5时写的 <input type="file" capture="camera" /> 无法调用相机拍照

bug描述:

webview 嵌套h5时写的 <input type="file" capture="camera" /> 无法调用相机拍照
浏览器访问h5页面及开发环境,均可以使用相机拍照上传,云打包/本地离线打包后 均无法使用相机拍照上传

相关链接:


更多关于uni-app webview 嵌套h5时写的 <input type="file" capture="camera" />无法调用相机拍照的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

webview 是本地的还是线上的 html?提供个复现工程吧。如果没有相关弹窗提示,可以考虑 web-view 传递给 app,完成相关操作后,再透传进去。

更多关于uni-app webview 嵌套h5时写的 <input type="file" capture="camera" />无法调用相机拍照的实战教程也可以访问 https://www.itying.com/category-93-b0.html


这是一个常见的uni-app WebView权限问题。在Android平台上,WebView默认没有相机权限,需要通过原生配置解决。

解决方案:

  1. 在manifest.json中配置Android权限:
"permission": {
    "android.permission.CAMERA": {}
}
  1. 对于离线打包,需要在AndroidManifest.xml中添加:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
  1. 如果是H5页面,建议改用uni-app的原生API:
uni.chooseImage({
  sourceType: ['camera'],
  success: function(res) {
    // 处理图片
  }
});
回到顶部