Java tutorial
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; import android.hardware.Camera; public class Main { static Method setPreviewCallbackWithBufferMethod; /** Sets the given callback object on the given camera. Calls setPreviewCallbackWithBuffer if the Android API supports it, * otherwise calls setPreviewCallback. */ public static boolean setPreviewCallbackWithBuffer(Camera camera, Camera.PreviewCallback callback) { if (setPreviewCallbackWithBufferMethod == null) { camera.setPreviewCallback(callback); return false; } try { setPreviewCallbackWithBufferMethod.invoke(camera, callback); return true; } catch (Exception ignored) { camera.setPreviewCallback(callback); return false; } } }