Nexus 4 camera flash doesn't fire when focus mode is set to continuous-picture
Asked Answered
F

2

5

I've encountered a strange issue, specifically on a Nexus 4 (though it may exist on other devices), where the camera flash won't fire when the focus mode is set to FOCUS_MODE_CONTINUOUS_PICTURE. The same code works fine on a Galaxy Nexus running the same version of Android (4.2.1). Has anyone encountered this problem before? I can fix the issue by simply switching the focus mode to FOCUS_MODE_AUTO. I'm hoping there is an easy work around for this issue, since the continuous picture focus mode is pretty crucial.

Freer answered 9/1, 2013 at 0:22 Comment(5)
I have some reason to believe that the Nexus 4 doesn't correctly support this mode, and setting it basically causes the driver to ignore other configuration. This might explain why the torch settings have no effect in this case.Pliam
@SeanOwen yeah, I'm starting to think I'm going to have to switch to FOCUS_MODE_AUTO on all devices.Freer
@Freer why not only use FOCUS_MODE_AUTO for the Nexus 4? Get the device model by logging Build.MODEL, then if(Build.MODEL.equals(NEXUS_4)) setFocus(FOCUS_MODE_AUTO); else setFocus(FOCUS_MODE_CONTINUOUS_PICTURE);Moulding
@JasonRobinson I was trying to avoid having hardware specific logic in my code, but I'm starting to think that this is the only way to go with camera issues.Freer
@Freer From my experience, it's the unfortunate case. With such a large variety of different devices, all with their own different camera architecture, not all of them play nicely with the Android SDK.Moulding
P
4

(For what it's worth just wrapping up my comment in an answer.)

The reason I suspect that continuous focus doesn't work on the Nexus 4 is that I have heard some rumblings from the Barcode Scanner user base about this (I'm the author). The Nexus 4 doesn't seem to work with, or without continuous focus enabled.

I haven't seen more detail to confirm/deny this, but, I have certainly seen this exact form of problem on other devices. In particular the Galaxy S2 seems to have some bad focus bugs.

It manifests as something slightly different: there is some third parameter you are setting which should be supported, or says it's supported, but actually causes the driver to barf. Then it doesn't honor the focus or torch setting. It may be that continuous focus, and torch, work. But a third setting is tripping it up.

Look into the logcat output. You should see debug messages from the driver. The exact nature depends a lot on the firmware. But in cases like this you will likely see errors in the driver. I usually see "unsupported parameter X" and cryptic numbers; sometimes it's much clearer about what it didn't like.

This may give you a lead, that it is in fact something like scene mode or metering area that are the problem. (And I have seen each of those cause this problem on at least one device.)

I also have a Galaxy Nexus and have never observed any problems of this form on it.

I'll also say that continuous focus can work nicely on some devices; it is worse on some devices like my old Desire HD, than the simple auto-focus mode. YMMV; I concluded it wasn't necessarily helpful so made regular auto focus the default in Barcode Scanner.

Pliam answered 7/2, 2013 at 21:48 Comment(4)
Thanks Sean, I really appreciate the insight. I've awarded you the bounty for taking the time to provide such a well written response. I actually spent a little bit of time digging into the zxing code at one point to try and solve this. I looked through my logcat output and couldn't find anything obvious. I think I'm going to make FOCUS_MODE_AUTO the default. I've noticed the Galaxy Nexus doesn't periodically focus when in this mode. Any suggestions for when to trigger auto focus?Freer
The regular auto-focus mode isn't automatic -- you have to trigger a focus cycle each time you want it. In the code we listen for the callback, wait, and ask for another focus. You can imitate that loop.Pliam
That was my understanding, but I've observed the Nexus 4 trying to auto focus periodically in that mode. Any idea why that might be the case?Freer
I don't have the device but that sounds like incorrect behavior. It is supposed to be a one shot call. In earlier versions of Android there was an API call that requested continuous focus events until cancelled. Its deprecated though and I bet you aren't calling this.Pliam
M
0

There are lot of issues on camera on Nexsus 4.

Firstly please try parameters.getSupportedFocusModes()

To restore continues autofocus, just call "cancelAutoFocus()" on the camera in your "AutoFocusCallback.java",

{
if (autoFocusHandler != null) {
  camera.cancelAutoFocus(); 
  ...
}

This call has no effect if the focus mode is "FOCUS_MODE_AUTO", because the the autofocus is finished anyway when onAutoFocus() gets called. But it restores the continuous autofocus when "FOCUS_MODE_CONTINUOUS_PICTURE" is used.

Hope it helps.I will work more and update.

Marathon answered 7/2, 2013 at 11:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.