• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to get auto focus distance from camera2 api

meetharia

Lurker
I want to get AutoFocus Distance in diopters from Camera2 API. But whenever i use result.get(CameraCharachteristics.LENS_FOCUS_DISTANCE) to get focus distance in diopters, the app crashes... I mean it works on my Nexus 5 phone but not in other phones... Is there any other way to get camera focus distances in diopters without causing the app to crash? Camera is configured in auto focus mode. Please help
 
Actually i needed an alternative to compute Camera Focus Distances. There are few devices which give output as null when CaptureResult.LENS_FOCUS_DISTANCE is executed. For eg. in Nexus 5, it will show the distances in diopters but in Lenovo Vibe k5 plus, it returns null. So i want an alternative to compute lens focus distance wherever the camera is configured in autofocus mode. Or is there any way to make camera focus at a particular distance?
Thanks
 
Hi Lurker meetharia,

Whenever I try getting the focus distance in camera2 using CaptureResult its always 0.0 can you please help

final CameraCaptureSession.CaptureCallback captureListener = new CameraCaptureSession.CaptureCallback() {
@override
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
super.onCaptureCompleted(session, request, result);
createCameraPreview();

focusValue = result.get(CaptureResult.LENS_FOCUS_DISTANCE);
}
 
Back
Top Bottom