2

Error in Android Studio. I have smartphone with android 4.4.2 and i can't instal the newer. What I should to do?

private CameraDevice.StateCallback mCameraDeviceStateCallback = new CameraDevice.StateCallback(){
    @Override
    public void onOpened(CameraDevice camera){
        mCameraDevice = camera;
    }
    @Override
    public void onDisconnected(CameraDevice camera){
        camera.close();
        mCameraDevice = null;
    }
    @Override
    public void onError(CameraDevice camera, int error){
        camera.close();
        mCameraDevice = null;
    }
};
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
  • You can dynamically check the OS version of the device you are running on and only use this call if it is high enough. You can't use it on older devices. – Henry Oct 17 '16 at 05:26

1 Answers1

1

Strictly speaking this is not correct way of solving this problem but you can still use old camera with new devices, just put 2-3 seconds delay on camera start like this:

final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mCamera.startPreview();
                }
            }, 2000);

This will work in the majority of cases, if you really have to support devices both older than 21 and newer than 23.

Valeriya
  • 1,067
  • 2
  • 16
  • 31