Android examples for android.hardware:Open Camera
block Until Open Camera
import android.hardware.camera2.CameraDevice; import android.hardware.camera2.CameraManager; import android.os.Handler; import android.util.Log; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; public class Main{ /**/*from www . j a v a 2s. co m*/ * @return true if success to open camera, false otherwise. */ public static boolean blockUntilOpenCamera(CameraManager cameraManager, Handler handler) { try { String[] cameraIdList = cameraManager.getCameraIdList(); if (cameraIdList == null || cameraIdList.length == 0) { return false; } String cameraId = cameraIdList[0]; CameraCallback callback = new CameraCallback(); cameraManager.openCamera(cameraId, callback, handler); return callback.waitForResult(); } catch (Exception ex) { // No matter what is going wrong, it means fail to open camera. ex.printStackTrace(); return false; } } }