uni-app 3.3.3以后版本 plus.camera.getCamera拍照出现黑屏问题
uni-app 3.3.3以后版本 plus.camera.getCamera拍照出现黑屏问题
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| HBuilderX | 3.3.5 | 云端 |
产品分类:HTML5+
手机系统:Android
手机系统版本号:Android 9.0
手机厂商:华为
手机机型:荣耀9
示例代码:
// 拍照 function captureImage(obj){ console.log( “sdfdsf”); var indid=parseInt(obj.getAttribute(“indid”)); vm.imgindex=indid; var cmr = plus.camera.getCamera(); var res = cmr.supportedImageResolutions[0]; var fmt = cmr.supportedImageFormats[0]; //console.log("Resolution: “+res+”, Format: "+fmt); cmr.captureImage( function( path ){ //vm.viewimg[vm.imgindex]={‘url’:path,‘upimg’:true}; createUpload(‘file://’+plus.io.convertLocalFileSystemURL(path)); //console.log( "Capture image success: " + path ); }, function( error ) { console.log( "Capture image failed: " + error.message ); }, {resolution:res,format:fmt,crop:{width:1024,height:1024}} ); }
更多关于uni-app 3.3.3以后版本 plus.camera.getCamera拍照出现黑屏问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html
上面代码测试没复现问题,麻烦提供一个完整的demo
更多关于uni-app 3.3.3以后版本 plus.camera.getCamera拍照出现黑屏问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html
不是所有机型都会有问题,我手边用的机型是荣耀9,安卓9.0系统,乐视s1 安卓6.0系统!看到也有人发贴说一样的问题,比如:https://ask.dcloud.net.cn/question/137065
我这里有问题的是安卓9.0系统和安卓6.0系统。
不设置crop:{width:1024,height:1024}这个裁图参数就会不会黑屏。
重要的事说三篇:
本人测试机型有限:只发现安卓9.0系统和安卓6.0系统有问题。
本人测试机型有限:只发现安卓9.0系统和安卓6.0系统有问题。
本人测试机型有限:只发现安卓9.0系统和安卓6.0系统有问题。
安卓10 安卓11及HarmonyOS 没有这个问题。
设置crop参数,然后使用相册,也会黑屏
回复 makeit: 不设置crop是正常的吗?
回复 DCloud_Android_zl: 是的!不设crop是正常的
回复 老向: 能复现问题的手机详细信息麻烦发一下吧,我这边试一下
回复 DCloud_Android_zl: 不设置crop 正常
回复 DCloud_Android_zl: 你去找几台安卓9.0系统和安卓6.0系统。就能重现,我的测试机型是:荣耀9手机系统是安卓9.0。乐视s1手机系统是安卓6.0。
回复 老向: 好的,我先找同类型的手机测试一下
设置crop参数,然后使用相册,也会黑屏
这是一个已知的兼容性问题。在 uni-app 3.3.3 及更高版本中,plus.camera.getCamera() API 在某些 Android 设备上调用 captureImage 方法时会出现黑屏或闪退。
主要原因: 新版 uni-app 底层引擎调整了相机权限和生命周期管理机制,与部分设备(特别是华为/荣耀等EMUI系统)的相机硬件兼容性出现问题。
解决方案:
-
降级 uni-app 版本: 将 HBuilderX 降级到 3.3.2 或更早版本可以临时解决,但这不是长期方案。
-
使用条件编译调用原生方法: 在
App.vue或需要拍照的页面中,通过条件编译直接调用 Android 原生相机:// #ifdef APP-PLUS const context = plus.android.importClass('android.content.Context'); const intent = plus.android.importClass('android.content.Intent'); const MediaStore = plus.android.importClass('android.provider.MediaStore'); function captureImage() { const main = plus.android.runtimeMainActivity(); const intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); main.startActivityForResult(intent, 0); } // #endif -
改用 uni.chooseImage API: 这是官方推荐的方式,兼容性更好:
uni.chooseImage({ count: 1, sourceType: ['camera'], success: (res) => { const tempFilePath = res.tempFilePaths[0]; // 处理拍照结果 } });

