Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for camera on Android 1.6 (SDK 4)

I have searched this server for the answer to this question but I haven't found one. I have only found it for Android 2.0 (SDK 5). So does anybody know how to find out whether there is a camera in Android 1.6 application? Can I check if the camera has autofocus.

Thank you for your answers, saric.

like image 203
saric Avatar asked Nov 14 '22 23:11

saric


1 Answers

Here is code to check if there is a camera ( https://developer.android.com/guide/topics/media/camera.html ):

/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance(){
    Camera c = null;
    try {
        c = Camera.open(); // attempt to get a Camera instance
    }
    catch (Exception e){
        // Camera is not available (in use or does not exist)
    }
    return c; // returns null if camera is unavailable
}

From the Android Compatibility page ( https://developer.android.com/guide/practices/compatibility.html ):

Android 1.0 through 1.5 required a 2 megapixel camera with auto-focus. However, with version 1.6, Android devices were permitted to omit the auto-focus capability, though a (fixed-focus) camera was still required. Some apps such as barcode scanners do not function as well with cameras that do not auto-focus. To prevent users from having a bad experience with those apps, existing apps that obtain permission to use the Camera were assumed by default to require auto-focus. This allowed Google Play to filter those apps from devices that lack auto-focus.

Looking at the API here: https://developer.android.com/reference/android/hardware/Camera.html#autoFocus%28android.hardware.Camera.AutoFocusCallback%29

It looks like they tell you to use a function that isn't present yet.

Unfortunately it may not be possible to check if the camera has auto-focus in Android 1.6.

like image 131
Joe Avatar answered Jan 06 '23 16:01

Joe