Camera camera = Camera.open(); camera.autoFocus(new Camera.AutoFocusCallback() { @Override public void onAutoFocus(boolean success, Camera camera) { // do something after autofocus completes } }); // cancel the autofocus process after 5 seconds new Handler().postDelayed(new Runnable() { @Override public void run() { camera.cancelAutoFocus(); } }, 5000);
@Override public void onPause() { super.onPause(); // release the camera and cancel any ongoing autofocus if(camera != null) { camera.cancelAutoFocus(); camera.setPreviewCallback(null); camera.release(); camera = null; } }This example cancels any ongoing auto-focus when the activity containing the camera is paused. The package library for the "Camera" class is "android.hardware".