Phil
Phil

Reputation: 25

How to find out technical data about the camera on an Android device?

I want to read out technical data of the installed camera(s) on an Android device (such as: image format, resolution, other technical details), because I eventually want to capture the video stream from the camera and then postprocess it (e.g. compress + stream it). So I'd really like to know what kind of video/picture signal/format the camera returns so that I can work with that.

Is there any way of doing this? I found the getCameraInfo() method, but this merely returns rather not-so-interesting information.

Upvotes: 0

Views: 834

Answers (1)

Chintan Rathod
Chintan Rathod

Reputation: 26034

You can find such information with following method.

private static Map<String, String> getFullCameraParameters(Camera cam) {
    Map<String, String> result = new HashMap<String, String>(64);
    final String TAG = "Home";

    try {
        Class camClass = cam.getClass();

        // Internally, Android goes into native code to retrieve this String
        // of values
        Method getNativeParams = camClass
                .getDeclaredMethod("native_getParameters");
        getNativeParams.setAccessible(true);

        // Boom. Here's the raw String from the hardware
        String rawParamsStr = (String) getNativeParams.invoke(cam);

        // But let's do better. Here's what Android uses to parse the
        // String into a usable Map -- a simple ';' StringSplitter, followed
        // by splitting on '='
        //
        // Taken from Camera.Parameters unflatten() method
        TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(
                ';');
        splitter.setString(rawParamsStr);

        for (String kv : splitter) {
            int pos = kv.indexOf('=');
            if (pos == -1) {
                continue;
            }
            String k = kv.substring(0, pos);
            String v = kv.substring(pos + 1);
            result.put(k, v);
        }

        // And voila, you have a map of ALL supported parameters
        return result;
    } catch (NoSuchMethodException ex) {
        Log.e(TAG, ex.toString());
    } catch (IllegalAccessException ex) {
        Log.e(TAG, ex.toString());
    } catch (InvocationTargetException ex) {
        Log.e(TAG, ex.toString());
    }

    // If there was any error, just return an empty Map
    Log.e(TAG, "Unable to retrieve parameters from Camera.");
    return result;
}

To use this method,

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    camera = Camera.open();
    Map<String, String> info = getFullCameraParameters(camera);
}  

@Override
protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
    camera.release();
}

Take permission in manifest like below.

<uses-permission android:name="android.permission.CAMERA"/>

I got following information in info object. I actually put a debug point for it and then fetch following information. Because i don't know keys. :)

{preferred-preview-size-for-video=176x144, zoom=0, mce=enable, hfr-size-values=, zoom-supported=true, strtextures=OFF, zsl-values=off,on, sharpness=10, hdr-values=, contrast=5, whitebalance=auto, max-sharpness=30, scene-mode=auto, jpeg-quality=85, preview-format-values=yuv420sp,yuv420p,yuv420p, rotation=0, histogram-values=, jpeg-thumbnail-quality=90, preview-format=yuv420sp, overlay-format=265, metering-areas=(-1000,-1000,1000,1000,1000), video-size-values=640x480,640x368,512x288,384x288,352x288,320x240,176x144, skinToneEnhancement=disable, preview-size=640x480, focal-length=1.15, auto-exposure-values=frame-average,center-weighted,spot-metering, video-zoom-support=false, iso=auto, denoise=denoise-off, mce-values=enable,disable, preview-frame-rate-values=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30, power-mode-supported=false, max-num-metering-areas=1, semc-metering-mode=center-weighted, preview-frame-rate=30, focus-mode-values=infinity,fixed, jpeg-thumbnail-width=512, scene-mode-values=auto,night,snow,sports, preview-fps-range-values=(1000,15000),(1000,30000), auto-exposure=frame-average, jpeg-thumbnail-size-values=512x288,480x288,432x288,512x384,352x288,0x0, histogram=disable, zoom-ratios=100,102,104,107,109,112,114,117,120,123,125,128,131,135,138,141,144,148,151,155,158,162,166,170,174,178,182,186,190,195,200,204,209,214,219,224,229,235,240,246,251,257,263,270,276,282,289,296,303,310,317,324,332,340,348,356,364,373,381,390,400, camera-mode=0, preview-size-values=640x480,640x368,512x288,384x288,352x288,320x240,176x144, picture-size-values=2048x1536,1920x1080,1632x1224,1280x960,1280x720,640x480,320x240, touch-af-aec=touch-on, preview-fps-range=1000,30000, min-exposure-compensation=-6, antibanding=off, touch-af-aec-values=touch-off,touch-on, max-num-focus-areas=0, vertical-view-angle=42.5, luma-adaptation=3, horizontal-view-angle=54.8, jpeg-thumbnail-height=384, smooth-zoom-supported=true, focus-mode=fixed, max-saturation=10, semc-metering-mode-values=frame-average,center-weighted,spot, max-contrast=10, video-frame-format=yuv420sp, hdr=disable, picture-format-values=jpeg,raw, max-exposure-compensation=6, focus-areas=(-1000,-1000,1000,1000,1000), num-snaps-per-shutter=1, exposure-compensation=0, exposure-compensation-step=0.333333, scene-detect=off, picture-size=640x480, max-zoom=60, saturation=5, whitebalance-values=auto,incandescent,fluorescent,daylight,cloudy-daylight, picture-format=jpeg, focus-distances=0.100000,0.150000,Infinity, zsl=off, touchAfAec-dx=100, lensshade-values=disable, touchAfAec-dy=100, iso-values=auto,ISO_HJR,ISO100,ISO200,ISO400,ISO800,ISO1600, lensshade=enable, antibanding-values=off,50hz,60hz,auto}

Upvotes: 1

Related Questions