How to autofocus Android camera automatically?

For me this worked a treat: //set camera to continually auto-focus Camera.Parameters params = c.getParameters(); //*EDIT*//params.setFocusMode(“continuous-picture”); //It is better to use defined constraints as opposed to String, thanks to AbdelHady params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); c.setParameters(params);

How to get uri of captured photo?

Follow below steps. Step – 1 : Create provider_paths.xml in res/xml folder and write below code in it. <?xml version=”1.0″ encoding=”utf-8″?> <paths xmlns:android=”http://schemas.android.com/apk/res/android”> <external-path name=”external_files” path=”.” /> </paths> Step – 2 : Declare provider in manifest as below. <provider android:name=”android.support.v4.content.FileProvider” android:authorities=”${applicationId}.provider” android:exported=”false” android:grantUriPermissions=”true”> <meta-data android:name=”android.support.FILE_PROVIDER_PATHS” android:resource=”@xml/provider_paths” /> </provider> If you are facing error at: android:name=”android.support.v4.content.FileProvider” … Read more

Camera on Android Eclipse emulator:

In the current release of the emulator (Ice Cream Sandwich, API14;Linux), web camera support is available. Google’s documentation and most answers available on the web do not yet reflect this. The emulator itself does: emulator -help … -fake-camera <mode> set fake camera emulation mode -webcam name=<name>[,dir=&lt;direction&gt;] setup web camera emulation … emulator -help-all and further: … Read more

Calling camera from an activity, capturing an image and uploading to a server

in my case i use this: when i click on save button pic is save and return me path in filePath variable. String filePath = Environment.getExternalStorageDirectory() +”/your_image_name.jpeg”; File file = new File(filePath); Uri output = Uri.fromFile(file); Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, output); and in onactivityresul() i use this “filePath” .

How can I open front camera using Intent in android?

java Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri photoUri = Uri.fromFile(getOutputPhotoFile()); intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); intent.putExtra(“android.intent.extras.CAMERA_FACING”, 1); startActivityForResult(intent, CAMERA_PHOTO_REQUEST_CODE); Other/Alternate Solution 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) { … Read more

Converting YUV_420_888 to JPEG and saving file results distorted image

Solution provided by @volodymyr-kulyk does not take into consideration the row stride of the planes within the image. Below code does the trick (image is of android.media.Image type): data = NV21toJPEG(YUV420toNV21(image), image.getWidth(), image.getHeight(), 100); And the implementations: private static byte[] NV21toJPEG(byte[] nv21, int width, int height, int quality) { ByteArrayOutputStream out = new ByteArrayOutputStream(); YuvImage … Read more

Turn ON/OFF Camera LED/flash light in Samsung Galaxy Ace 2.2.1 & Galaxy Tab

I will soon released a new version of my app to support to galaxy ace. You can download here: https://play.google.com/store/apps/details?id=droid.pr.coolflashlightfree In order to solve your problem you should do this: this._camera = Camera.open(); this._camera.startPreview(); this._camera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { } }); Parameters params = this._camera.getParameters(); params.setFlashMode(Parameters.FLASH_MODE_ON); this._camera.setParameters(params); params = this._camera.getParameters(); … Read more

switch back/front camera on fly

In onCreate() of my activity I add the following onClick listener to a button overlayed on my Preview SurfaceView (there are numerous example on the web for previewing): ImageButton useOtherCamera = (ImageButton) findViewById(R.id.useOtherCamera); //if phone has only one camera, hide “switch camera” button if(Camera.getNumberOfCameras() == 1){ useOtherCamera.setVisibility(View.INVISIBLE); } else { useOtherCamera.setOnClickListener(new View.OnClickListener() { @Override public … Read more