相机回调不适用于版本8.1

时间:2018-08-04 18:10:54

标签: android sdk android-camera

我需要帮助弄清楚为什么我的代码在版本8.1的Android设备上无法正常工作,同一段代码在版本8.0及以下版本上可以正常工作。

minSdkVersion = 19 targetSdkVersion = 26 compileSdkVersion = 26

在某些情况下,当多次密码尝试失败时,我正在通过相机拍摄照片,该应用程序在前台运行。该应用会调用此方法,为相机设备做准备,并提供JPEG格式的PictureCallback。

在日志中我可以看到

  

takePicture被称为

但是,onPictureTaken不会被调用。

代码如下:

        sLogger.info(TAG + "takePicture called.");
    try {
        mCamera.takePicture(null, null, null, new PictureCallback() {
            @Override
            public void onPictureTaken(byte[] data, Camera camera) {
                if (data == null) {
                    sLogger.error(TAG + "Received null data in onPictureTaken from Camera PictureCallBack");
                    return;
                }
                pictureTaken(data, orientation);
            }
        });
    } catch (Exception e) {
        lookoutCamFailed();
        sLogger.error(TAG + "takePicture failed.", e);

    }

添加日志:

  

07-20 01:22:20.206 1264 2946 D ActivityManager性能:AMP_release()ACT_START

     

07-20 01:22:20.225 27040 29514 I MyApp:[CameraManager.initPreview:742]凸轮:预览开始。

     

07-20 01:22:20.226 599 1485 I QCamera:getCameraInfo:392:E摄像机ID(1),mNumOfCameras(2)

     

07-20 01:22:20.226 599 1485 I QCamera:getCamInfo:8789:相机1资源成本为100

     

07-20 01:22:20.226 599 1485 I QCamera:getCameraInfo:409:摄像机ID = 1,面向信息=前

     

07-20 01:22:20.227 599 1485 E QCamera:checkCameraCondition:1061:摄像机ID(1),摄像机朝向(1),摄像机类型(1)

     

07-20 01:22:20.227 599 1485 I QCamera:getCameraInfo:424:X摄像机ID(1)

     

07-20 01:22:20.230 855 2354 D CameraClient:sendCommand(pid 27040)   07-20 01:22:20.230 855 2354 D CameraClient:ENABLE_SHUTTER_SOUND(0,0)   07-20 01:22:20.230 855 2354 D CameraClient:enableShutterSound(pid 27040)

     

07-20 01:22:20.230 27040 29514 I MyApp:[CameraManager.disableShutterSoundIfPossible:531] MyAppCam:调用enableShutterSound成功。

     

07-20 01:22:20.231 27040 29514我MyApp:[CameraManager.prepAndTakePicture:863] MyAppCam:已调用takePicture。

     

07-20 01:22:20.231 855 2354 D CameraClient:takePicture(pid 27040):0x100

     

07-20 01:22:20.232 855 2354 D CameraClient:enableMsgType:msg(0x100,0xd0d)

     

07-20 01:22:20.232 855 2354 D SecCameraCoreManager:enableMsgType:msg(In:0x100,Out:0xd0d)

     

07-20 01:22:20.232 855 2354 I ShotCommon:enableMsgType:msg(In:0x100,Out:0xd0d)

     

07-20 01:22:20.232 855 2354 D SecCameraCoreManager:takePicture   07-20 01:22:20.234 1264 1447 I EDMNativeHelperService:isCameraEnabled   07-20 01:22:20.235 1264 1447 D RestrictionPolicy:isCameraEnabled ret(true)userId(0)cxtInfo.mCallerUid(10034)cxtInfo.mContainerId(0)

     

07-20 01:22:20.235 855 2354 E SecCameraCoreManager:checkTemperature(0)

     

07-20 01:22:20.235 855 2354 D SecCameraCoreManager:takePicture:停止IT策略检查线程

     

07-20 01:22:20.283 599 29526 I QCamera:procEvtPreviewReadyState:924:QCAMERA_SM_EVT_GET_PARAMS ReadyState

     

07-20 01:22:20.285 855 2354 D ShotSingle:takePicture:supportedPictureFormat = jpeg,nv21

     

07-20 01:22:20.285 855 2354 I ShotSingle:takePicture:将图片格式备份为jpeg

     

07-20 01:22:20.285 855 2354 I Shot单张:takePicture:正常,jpeg   07-20 01:22:20.285 599 1485 I QCamera:拍摄照片:1391:[KPI性能]拍摄照片:E PROFILE_TAKE_PICTURE相机ID 1

     

07-20 01:22:20.286 599 1485 I QCamera:take_picture:1409:[KPI Perf] take_picture:X

     

07-20 01:22:20.286 599 29604 I QCamera:take_picture_thread:1073:[KPI Perf] take_picture_thread:E

     

07-20 01:22:20.286 599 29604 I QCamera:take_picture_internal:1105:[KPI Perf] take_picture_internal:E摄像机ID 1

     

07-20 01:22:20.286 599 29604 I QCamera:take_picture_internal:1229:take_picture_internal Flash模式= 0,LLS模式= 0,自动LLS模式= 0,NumOfSnaps = 1

     

07-20 01:22:20.286 599 29526 E QCamera:procEvtPreviewReadyState:1099:错误!!无法在状态(1)中处理evt(25)

     

07-20 01:22:20.286 599 29604 I QCamera:take_picture_internal:1361:[KPI Perf] take_picture_internal:X

     

07-20 01:22:20.287 599 29604 I QCamera:take_picture_thread:1077:[KPI Perf] take_picture_thread:X

     

07-20 01:22:20.287 27040 29514 I MyApp:[CameraManager $ 4.run:779] MyAppCam:surfaceDestroyed被调用。

     

07-20 01:22:20.321 2750 2750数据状态:!@ 179,0 r 553172 42202994 w 299093 5907016 d 11954 2375296 f 81990 82006 iot 648070 657873 th 51200 0 0 pt 0 inp 0 0 67436.843

     

07-20 01:22:20.330 1264 2292 W合子:与所有者Binder:1264_1E(12984)在android.content.pm.ParceledListSlice com.android.server.pm.PackageManagerService.getInstalledPackages(int,int )(PackageManagerService.java:11443)android.content.pm.ApplicationInfo com.android.server.pm.PackageManagerService.getApplicationInfoInternal(java.lang.String,int,int,int)中的waiters = 0

     

07-20 01:22:20.331 1264 2259 W合子:与所有者Binder:1264_1E(12984)在android.content.pm.ParceledListSlice com.android.server.pm.PackageManagerService.getInstalledPackages(int,int )(PackageManagerService.java:11443)java.lang.String com.android.server.pm.PackageManagerService.getInstantAppPackageName(int)中的waiters = 1持续了481ms

     

07-20 01:22:20.335 1264 2293 W合子:与int com上的所有者Binder:1264_D(2292)长时间监视竞争

1 个答案:

答案 0 :(得分:0)

来自文档;看来必须先开始预览才能拍摄照片。您有相机绑定的表面视图吗?

This method is only valid when preview is active (after startPreview()). Preview will be stopped after the image is taken;

以上内容来自api docs

值得一提的是不建议使用Camera API;如果您将来打算维护此应用,则需要使用Camera2!