List of usage examples for android.hardware Camera open
public static Camera open()
From source file:Main.java
public static Camera getCameraInstance() { Camera mCamera = null;/* w w w. j a v a 2 s. c o m*/ try { mCamera = Camera.open(); } catch (Exception e) { } return mCamera; }
From source file:Main.java
@Nullable public static Camera getCameraInstance() { Camera c = null;//from w ww. j av a 2 s. co m try { c = Camera.open(); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } return c; }
From source file:Main.java
private static void checkCamera() { if (camera == null) camera = Camera.open(); }
From source file:MainActivity.java
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { mCamera = Camera.open(); if (mCamera != null) { try {/*ww w . ja va2 s . c o m*/ mCamera.setPreviewTexture(surface); mCamera.startPreview(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.macleod2486.androidswissknife.components.Flashlight.java
private void turnOnLight() { Log.i("Flashlight", "Toggling on light"); try {/*from w ww .java2 s.co m*/ cam = Camera.open(); p = cam.getParameters(); p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); cam.setParameters(p); SurfaceTexture mPreviewTexture = new SurfaceTexture(0); cam.setPreviewTexture(mPreviewTexture); cam.startPreview(); torchOn = true; } catch (Exception ex) { torchOn = false; Log.e("Flashlight", ex.toString()); } }
From source file:com.amazonaws.devicefarm.android.referenceapp.Fragments.Tabs.Native.Native_CameraFragment.java
@Override public void surfaceCreated(SurfaceHolder holder) { try {//from w w w . ja v a 2s .c o m camera = Camera.open(); camera.setDisplayOrientation(90); Camera.Parameters parameters = camera.getParameters(); camera.setParameters(parameters); camera.setPreviewDisplay(surfaceHolder); camera.startPreview(); surfaceView.setContentDescription(getString(R.string.camera_preview_on)); } catch (Exception e) { Log.e(CAMERA_FRAGMENT_TAG, String.valueOf(e)); } }
From source file:net.patchingzone.ru4real.nuevo.TorchActivityPlugin.java
private void getCamera() { if (mCamera == null) { try {//from w ww . j av a 2s . c o m mCamera = Camera.open(); } catch (RuntimeException e) { Log.i(TAG, "Camera.open() failed: " + e.getMessage()); } } }
From source file:com.googlecode.android_scripting.facade.CameraFacade.java
public Camera openCamera(int cameraId) throws Exception { int sSdkLevel = android.os.Build.VERSION.SDK_INT; Camera result;/*from w ww . j a va 2 s. co m*/ if (sSdkLevel < Build.VERSION_CODES.GINGERBREAD) { result = Camera.open(); } else { Method _open = Camera.class.getMethod("open", int.class); try { result = (Camera) _open.invoke(null, cameraId); } catch (InvocationTargetException e) { Throwable th = e.getCause(); String s = th.getMessage(); Log.e("error: " + s); result = null; } } return result; }
From source file:com.dimasdanz.kendalipintu.BarcodeOpenDoorActivity.java
public static Camera getCameraInstance() { Camera c = null;/*from w ww .j a va 2 s. c o m*/ try { c = Camera.open(); } catch (Exception e) { } return c; }
From source file:com.mienaikoe.deltamonitor.CameraWatcherService.java
public void startRecording() { if (camera == null) { try {/*from w w w .java 2 s . c o m*/ camera = Camera.open(); } catch (Exception ex) { Log.e(TAG, ex.getMessage()); ex.printStackTrace(); return; } if (camera == null) { Log.e(TAG, "Camera is null despite trying to allocate it. Stopping Service"); throw new IllegalStateException("DeltaMonitor was unable to allocate the camera."); } } try { Log.i(TAG, "==================Beginning to Record"); if (buffer == null) { Camera.Parameters parameters = CameraSizer.sizeUp(camera); size = parameters.getPreviewSize(); buffer = new byte[size.height * size.width * ImageFormat.getBitsPerPixel(parameters.getPreviewFormat()) / 8]; } camera.addCallbackBuffer(buffer); if (texture == null) { texture = getTexture(); } camera.setPreviewTexture(texture); detector.reset(); camera.setPreviewCallbackWithBuffer(previewCallback); camera.startPreview(); } catch (IOException ex) { Log.e(TAG, "IOException during recording setup " + ex.getMessage()); ex.printStackTrace(); } }