Я решаю проблему с помощью следующего кода.
Хорошо работает с Galaxy S8, S8 +, S9, S9 +.
private val autoFocusExecutor = ScheduledThreadPoolExecutor(1)
fun startCamera() {
if (camera == null) {
camera = Camera.open()
if (camera == null) {
showCameraErrorMsg()
} else {
preview.camera = camera
capturereceipt_textview_cameraerrormsg.visibility = View.GONE
capturereceipt_framelayout_viewfinder.visibility = View.VISIBLE
autoFocusExecutor.schedule(Sc{
val params: Camera.Parameters = camera!!.parameters
if (params.getSupportedFocusModes()
.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
//TODO: Auto focus not working
params.focusMode = Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE
}
camera?.parameters = params
}, 1000, TimeUnit.MILLISECONDS)
}
}}