Raju Gujarati Raju Gujarati - 1 year ago 186
Android Question

Android setting manual focus by touching

I am going to set the my Android App by opening the camera and enable manual focus by touching the point in to camera. The camera can refocus to the point where I have pointed on to the screen. Would you please tell me the methodology or which component should I start with to modify ?

Below is my code:

public void takePhoto(File photoFile, String workerName, int width, int height, int quality) {
if (getAutoFocusStatus()){
camera.autoFocus(new AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
camera.takePicture(shutterCallback, rawCallback, jpegCallback);
camera.takePicture(shutterCallback, rawCallback, jpegCallback);

this.photoFile = photoFile;
this.workerName = workerName;
this.imageOutputWidth = width;
this.imageOutputHeight = height;

public void takePhoto(File photoFile, int width, int height, int quality) {
takePhoto(photoFile, null, width, height, quality);

Answer Source

Though this answer does not show how to focus in on a single area, it is definitely useful in showing how exactly to focus the camera to begin with.

Here is what i have done. This works on my device (Droid DNA by HTC), built in Android Studio

In both OnSurfaceChanged() and OnSurfaceCreated(), I have the following code: (mCamera is my private Camera object)

        Camera.Parameters p = mCamera.getParameters();


In the constructor, you must place


This will allow you to receive focus events. As for capturing them...

 public boolean onTouchEvent(MotionEvent event){
    if(event.getAction() == MotionEvent.ACTION_DOWN){
        Log.d("down", "focusing now");


    return true;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download