Android: How can I check if a device has Camera2 a

2020-02-01 03:44发布

问题:

Well, how can I check if an android device has Camera2 api features implemented or not? There are many new features in camera2 api such as manual controls. So how can I know whether, which Camera2 api features are implemented or not, programmatically?

回答1:

Actually, checking for API version 21+ will work. The camera2 API, including CameraManager is part of the system, not dependent on the hardware present. So you can always ask the CameraManager for a list of CameraDevices, which you can then query individually.

However, I think what you actually mean is "how can I tell if I can set photographic parameters manually using the camera2 API?", which is dependent on the device you have. It depends on what control you need, but the information you need can be gleaned by getting the REQUEST_AVAILABLE_CAPABILITIES metadata field. Hint: look for MANUAL_SENSOR.



回答2:

Indeed, the camera2 api is only supported from API level 21. But only this check is not enough. There are devices with API level 21, but that support the camera 2 only partially. To check this, you should check the value of CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL. It can be FULL, LEGACY or LIMITED. Check here for details: https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html

Here is how to get it:

CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);

for (String cameraId : manager.getCameraIdList()) {
                    CameraCharacteristics characteristics
                            = manager.getCameraCharacteristics(cameraId);


    Log.d("Img", "INFO_SUPPORTED_HARDWARE_LEVEL " + characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL));
 }


回答3:

I also needed this for another project, so I wrote a small app that probes all camera2 features and shows which ones are available on the phone: https://play.google.com/store/apps/details?id=de.weis.camera2probe

You can email this report in-app. I list all reports that I received here: https://github.com/TobiasWeis/android-camera2probe/wiki (The code of the app is also available there, in case someone needs to integrate into their own project)



回答4:

In cases if someone needs full snippet of how to determine which camera in the device has Camera2 API support (at least limited support):

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public boolean allowCamera2Support(int cameraId) {
        CameraManager manager = (CameraManager)getSystemService(Context.CAMERA_SERVICE);
        try {
            String cameraIdS = manager.getCameraIdList()[cameraId];
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraIdS);
            int support = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);

                if( support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY )
                    Log.d(TAG, "Camera " + cameraId + " has LEGACY Camera2 support");
                else if( support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED )
                    Log.d(TAG, "Camera " + cameraId + " has LIMITED Camera2 support");
                else if( support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_FULL )
                    Log.d(TAG, "Camera " + cameraId + " has FULL Camera2 support");
                else
                    Log.d(TAG, "Camera " + cameraId + " has unknown Camera2 support?!");

            return support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED || support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_FULL;
        }
        catch (CameraAccessException e) {
            e.printStackTrace();
        }
        return false;
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private void checkCamera2Support() {
        if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ) {
            int numberOfCameras = 0;
            CameraManager manager = (CameraManager)getSystemService(Context.CAMERA_SERVICE);

            try {
                numberOfCameras =  manager.getCameraIdList().length;
            } catch (CameraAccessException e) {
                e.printStackTrace();
            } catch(AssertionError e) {
                e.printStackTrace();
            }

            if( numberOfCameras == 0 ) {
                    Log.d(TAG, "0 cameras");
            }else {
                for (int i = 0; i < numberOfCameras; i++) {
                    if (!allowCamera2Support(i)) {
                        Log.d(TAG, "camera " + i + " doesn't have limited or full support for Camera2 API");
                    }else{
                        // here you can get ids of cameras that have limited or full support for Camera2 API
                    }
                }
            }
        }
    }


回答5:

Install the app: Manual Camera Compatibility. It checks for Manual Focus, WB, ISO, Shutter speed and RAW support. All exposed via the camera2 HAL driver. I've installed the above in the AT&T store to check phones before buying. A great way to know if you're buying yesterday's model.

https://play.google.com/store/apps/details?id=pl.vipek.camera2_compatibility_test&hl=en



回答6:

Install the App A Better Camera. You'll be able tout check if it is full, legacy, limited or mot supporter. That's how I found Samsung galaxy Tab 3 SMT820 iscamera2 api full.



回答7:

Camera API2

The Camera API2 framework exposes lower-level camera control to the app, including efficient zero-copy burst/streaming flows and per-frame controls of exposure, gain, white balance gains, color conversion, denoising, sharpening, and more. For details, watch the Google I/O video overview.

Android 5.0 and later includes Camera API2; however, devices running Android 5.0 and later may not support all Camera API2 features. The android.info.supportedHardwareLevel property that apps can query through the Camera API2 interfaces reports one of the following support levels:

LEGACY: These devices expose capabilities to apps through the Camera API2 interfaces that are approximately the same capabilities as those exposed to apps through the Camera API1 interfaces. The legacy frameworks code conceptually translates Camera API2 calls into Camera API1 calls; legacy devices do not support Camera API2 features such as per-frame controls.
LIMITED: These devices support some Camera API2 capabilities (but not all) and must use Camera HAL 3.2 or later.
FULL: These devices support all of major capabilities of Camera API2 and must use Camera HAL 3.2 or later and Android 5.0 or later.
LEVEL_3: These devices support YUV reprocessing and RAW image capture, along with additional output stream configurations.
EXTERNAL: These devices are similar to LIMITED devices with some exceptions; for example, some sensor or lens information may not be reported or have less stable frame rates. This level is used for external cameras such as USB webcams. 

This What is Camera2 API? Check if your Smartphone supports it may help you to find it out!