I am trying to use the camera class to take a picture programatically in an Android application. The target API is the newest (N as of writing this) but the minimum API is 15.
Prior to API level 21, this was the standard:
android.hardware.Camera camera = Camera.open();
camera.takePicture(foos, ro, da);
Now, it is deprecated, and they recommend you use this one
CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
manager.openCamera(foos, ro, da);
//A few more steps, but the key one here is the getSystemService call as it gives the warning
But the problem is that If I use the second one in my app, which has a minimum API of 15, it warns me that it will not work. (Screenshot Here), which seems like it will cause problems if used on devices with an API of < 21
Is there a 3rd, other class I should be using in this scenario to use the camera functionality? Am I missing something? Or should I really just run the if check for their build and if < 21, run the deprecated code and if >= 21, use the new code?
Thanks!
-PGMac
Edit 1: To clarify further, whenever Android deprecates something, I have seen them make the new, non-deprecated code, backwards compatible so that you don't need to use it anymore. A couple of examples would be: getColor, setBackgroundDrawable, and more. I know that here in this answer they indicate what I already mentioned, which is I could use an if check and compare, but my concern is that the deprecated class will eventually be unusable and cause the code to break. That's really the essence of this question, Is that fear justified? Should I just use an if check? Or is there a better way to do it by using a different class entirely?