Android deprecated android.hardware.Camera and now recommend using android.hardware.camera2 but this is not available in anything below API 21

bjohnson picture bjohnson · Jul 28, 2015 · Viewed 7.7k times · Source

I have an application that supports back to Android API 19 (KitKat) and there is heavy Camera use internally.

Currently, android.hardware.camera2 is the recommended way of using the camera API and android.hardware.Camera is deprecated.

Is there a way to support API 19 and stop using android.hardware.Camera without getting deprecation warnings in my build? If so, how?

The only other question I could find was this but it doesn't answer my question.

Answer

tyczj picture tyczj · Jul 28, 2015

you would use

if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    //use old camera API
}else{
    //use new camera API
}

then you can support what you want