tags:

views:

21

answers:

1

I am working with Augmented Reality application with android, and I implemented camera code.

My current base SDK version is 1.6. With this my application is working fine with devices having OS version upto 1.6 and getting problem with OS 2.0 and up..

Any solution ?

Thanks.

A: 

I googled and got the below solution.. Replace your surfacechanged method with below one

private static Method getSupportedPreviewSizes = null;
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {

    try {
        Camera.Parameters parameters = camera.getParameters();

        Integer version = Integer.parseInt(Build.VERSION.SDK);

        if (version >= Build.VERSION_CODES.ECLAIR) {

            try {
                getSupportedPreviewSizes = Parameters.class.getMethod(
                        "getSupportedPreviewSizes", (Class[]) null);
                /* success, this is a newer device */
            } catch (NoSuchMethodException nsme) {
                /* failure, must be older device */
            }

            Object supportedFormats = getSupportedPreviewSizes.invoke(
                    parameters, (Object[]) null);
            List<Size> sizes;
            if (supportedFormats instanceof List<?>) {
                sizes = (List<Camera.Size>) supportedFormats;// params.getSupportedPreviewSizes();
                Size optimalSize = getOptimalPreviewSize(sizes, w, h);
                parameters.setPreviewSize(optimalSize.width,
                        optimalSize.height);
            }
        } else {

            parameters.setPreviewSize(100, 100);
        }
        parameters.setPictureSize(320, 480);

        camera.setParameters(parameters);
        camera.startPreview();
    } catch (Exception e) {

        e.printStackTrace();
    }

}
Vishal