I need ONE function to check if front camera exist, and if so – show preview.
I found a few links, but each of them talk about a specific device:
- How do I open the "front camera" on the Android platform?
- http://developer.android.com/reference/android/hardware/Camera.html#open(int
- Front-facing camera on LG Optimus 2X Speed
- How to use Front Facing Camera on Samsung Galaxy S
Can anyone provide a generic code for this? Or maybe a combined code that will work with all devices?
For APIs >=9, you can use the
Cameraclass: http://developer.android.com/reference/android/hardware/Camera.html to see if it has more than one camera, and query theCameraInfogetNumberOfCamerasgetCameraInfo:http://developer.android.com/reference/android/hardware/Camera.CameraInfo.html
For APIs >=5, an option is to read
public List<Camera.Size> getSupportedPictureSizes (). Front facing cameras will usually have much lower max resolution than back cameras.http://developer.android.com/reference/android/hardware/Camera.Parameters.html