How to get camera result as a uri in data folder?

There are two ways to solve this problem. 1. Save bitmap which you received from onActivityResult method You can start camera through intent to capture photo using below code Intent cameraIntent=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(cameraIntent, CAMERA_REQUEST); After capture photo, you will get bitmap in onActivityResult method if (requestCode == CAMERA_REQUEST) { Bitmap photo = (Bitmap) data.getExtras().get(“data”); } … Read more

Android Camera Preview Stretched

I’m using this method -> based on API Demos to get my Preview Size: private Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) { final double ASPECT_TOLERANCE = 0.1; double targetRatio=(double)h / w; if (sizes == null) return null; Camera.Size optimalSize = null; double minDiff = Double.MAX_VALUE; int targetHeight = h; for (Camera.Size size : sizes) … Read more

How do I open the “front camera” on the Android platform?

private Camera openFrontFacingCameraGingerbread() { int cameraCount = 0; Camera cam = null; Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); cameraCount = Camera.getNumberOfCameras(); for (int camIdx = 0; camIdx < cameraCount; camIdx++) { Camera.getCameraInfo(camIdx, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { try { cam = Camera.open(camIdx); } catch (RuntimeException e) { Log.e(TAG, “Camera failed to open: ” + e.getLocalizedMessage()); … Read more

Android camera intent

private static final int TAKE_PICTURE = 1; private Uri imageUri; public void takePhoto(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File photo = new File(Environment.getExternalStorageDirectory(), “Pic.jpg”); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); imageUri = Uri.fromFile(photo); startActivityForResult(intent, TAKE_PICTURE); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case TAKE_PICTURE: if (resultCode == … Read more

How to turn on front flash light programmatically in Android?

For 2021, with CameraX, it is now dead easy: https://stackoverflow.com/a/66585201/294884 For this problem you should: Check whether the flashlight is available or not? If so then Turn Off/On If not then you can do whatever, according to your app needs. For Checking availability of flash in the device: You can use the following: context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); which … Read more