List of usage examples for android.hardware.camera2 CameraManager openCamera
@RequiresPermission(android.Manifest.permission.CAMERA) public void openCamera(@NonNull String cameraId, @NonNull @CallbackExecutor Executor executor, @NonNull final CameraDevice.StateCallback callback) throws CameraAccessException
From source file:com.example.camera2apidemo.Camera2Fragment.java
/** * Opens the camera specified by {@link Camera2Fragment#mCameraId}. *//*from www.ja va 2s.co m*/ private void openCamera(int width, int height) { if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { FragmentCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, 1); return; } mCameraId = setUpCameraOutputs(width, height); // ?CameraId???CameraIdCamera?CameraDevice Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { if (!mSemaphore.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } // ??CameraId // ?CameraDeviceStateCallback??CameraDevice // ?Handler?null? manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening.", e); } }
From source file:rqg.fantasy.rtmpdemo.Camera2BasicFragment.java
/** * Opens the camera specified by {@link Camera2BasicFragment#mCameraId}. *///from w w w. j av a2s . c o m private void openCamera(int width, int height) { Log.d(TAG, "openCamera() called with: width = [" + width + "], height = [" + height + "]"); if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { requestCameraPermission(); return; } setUpCameraOutputs(width, height); configureTransform(width, height); Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening.", e); } }
From source file:com.mgtv.qxx.ttsdemo.Camera2BasicFragment.java
/** * Opens the camera specified by {@link Camera2BasicFragment#mCameraId}. *//*from w w w . j a v a 2 s .c o m*/ private void openCamera(int width, int height) { // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ // if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) // != PackageManager.PERMISSION_GRANTED) { // requestCameraPermission(); // return; // } // }else { // targetSdkVersion < Android M, we have to use PermissionChecker if (PermissionChecker.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) != PermissionChecker.PERMISSION_GRANTED) { requestCameraPermission(); } // } setUpCameraOutputs(width, height); configureTransform(width, height); Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening.", e); } }
From source file:com.example.janicduplessis.myapplication.CameraFragment.java
/** * Opens the camera specified by {@link CameraFragment#mCameraId}. *//* w w w . ja v a 2 s.c om*/ private void openCamera(int width, int height) { //if (getActivity().checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { requestCameraPermission(); return; } setUpCameraOutputs(width, height); configureTransform(width, height); Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening.", e); } }
From source file:fbla.hhs.eclat.Camera.Camera2BasicFragment.java
/** * Opens the camera specified by {@link Camera2BasicFragment#mCameraId}. *//*from www .ja v a 2 s . c om*/ private void openCamera(int width, int height) { if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { requestCameraPermission(); return; } setUpCameraOutputs(width, height, cameraType /*CameraCharacteristics.LENS_FACING_FRONT*/); configureTransform(width, height); Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening.", e); } }
From source file:com.Yamate.Camera.Camera.java
/** * Opens the camera specified// ww w. j a va 2s .c o m */ private void openCamera(int width, int height) { setUpCameraOutputs(width, height); configureTransform(width, height); Activity activity = mActivity; //adding for camcorder mMediaRecorder = new MediaRecorder(); try { setUpMediaRecorder(); } catch (IOException e) { e.printStackTrace(); } CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening.", e); } catch (SecurityException e) { Log.e("mr", "cacPreviewSize - Security Exception"); } }
From source file:com.vest.album.fragment.CameraBasicFragment.java
/** * Opens the camera specified by {@link CameraBasicFragment#mCameraId}. *//*from ww w . j av a 2 s . com*/ private void openCamera(int width, int height) { if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { requestCameraPermission(); return; } setUpCameraOutputs(width, height); configureTransform(width, height); Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { callback.onPhotoError("?"); // throw new RuntimeException("Time out waiting to lock camera opening."); } manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler); } catch (CameraAccessException e) { callback.onPhotoError("?"); e.printStackTrace(); } catch (InterruptedException e) { callback.onPhotoError("?"); } }
From source file:research.dlsu.cacaoapp.Camera2BasicFragment.java
/** * Opens the camera specified by {@link Camera2BasicFragment#mCameraId}. *//*from ww w . j a v a 2s . c o m*/ private void openCamera(int width, int height) { if (ContextCompat.checkSelfPermission(getActivity().getBaseContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { requestCameraPermission(); return; } else { setUpCameraOutputs(width, height); configureTransform(width, height); Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening.", e); } } }
From source file:com.nightshadelabs.snappy.activity.Camera2BasicFragment.java
/** * Opens the camera specified by {@link Camera2BasicFragment#mCameraBackId}. *///from ww w .ja v a 2 s .c o m private void openCamera(int width, int height, String preferredCameraId) { if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { requestCameraPermission(); return; } setUpCameraOutputs(width, height); configureTransform(width, height); Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); if (preferredCameraId == null) { preferredCameraId = mCameraBackId; } mCurrentCameraId = preferredCameraId; try { if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } manager.openCamera(preferredCameraId, mStateCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening.", e); } }
From source file:research.dlsu.cacaoapp.Camera2BasicFragment1.java
/** * Opens the camera specified by {@link Camera2BasicFragment1#mCameraId}. *///from w ww.ja v a 2s .c om private void openCamera(int width, int height) { // if (ContextCompat.checkSelfPermission(getActivity().getBaseContext(), Manifest.permission.CAMERA) // != PackageManager.PERMISSION_GRANTED) { // requestCameraPermission(); // return; // }else { setUpCameraOutputs(width, height); configureTransform(width, height); Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening.", e); } // } }