Skip to main content
Inspiring
June 29, 2011
Question

Camera autofocus on Android

  • June 29, 2011
  • 6 replies
  • 10910 views

Hello, I'm making a QR scanner application. I'm testing my application on the Motorola Droid 2, which has an auto focus camera. For some reason, no matter what I do, the camera won't re-focus after focusing for the first time. I can force it to focus by doing a Camera.setMode call, but that causes the application to hang for about half a second. I have not had this problem when testing it with an iPhone 4. Does anyone know how I can remedy this situation?

Thank you in advance!

P.S. I also noticed that when I first initialize the camera/video, the autofocus happens twice. (The camera makes some sort of noise when it autofocuses, and it does it twice when I first open my app.)

This topic has been closed for replies.

6 replies

Participating Frequently
April 25, 2012

Guys,

Just to let you know, I've had some colleagues in Asia test various handsets they have for me and have reports of the following devices all corretly auto-focusing:

- Glaxy Nexus (ICS)

- HTC Sensation XE (ICS)

- Galaxy Note (GB)

- Galaxy Cooper (GB)

Haven't seen it first hand yet, but will be ordering a Nexus to test it.

Participating Frequently
May 2, 2012

Update: I have now seen continuous focus working on the HTC Sensation XE. I don't understand what the hardware differences with the S2 are, as it clearly is capable of continuous auto-focus, but Air certainly can work correctly on with the camera on some Android handsets.

Participating Frequently
April 24, 2012

I've been working on something else, so haven't looked at this for a while, but had a chance to take a look this morning.

Interestingly, continuous focus works on the S2 is you select the forward rather than read facing camera, which would tend to suggest this is device related??

Inspiring
April 24, 2012

It's very interesting that you managed to get continuous autofocus working on the Galaxy S2. I just went to double check whether or not Droid 2 actually supports continuous autofocus and I do get some youtube videos demonstrating this feature, so I'm going to assume it does. However, this is not reflected in the AIR application, sadly.

Recently, my team migrated our application over to PhoneGap to test how things would work there. The continuous autofocus seems to work properly for the Droid 2 using PhoneGap (uses native library, I assume). Also, the QR scanner is extraordinarily fast compared to the AIR implementation.

Participating Frequently
April 24, 2012

I'd be happy to switch to PhoneGap but I need to stream the video from the handset, something which is trivial using ActionScript but not possible as far as I can see with PhoneGap.

It's irritiating, as we do have native code for both Androad and iOS that does what we need, but I'd rather not have two separate code bases and this seemed like it would be an ideal way to do it, but not being able to have the focus update is something of a show stopper for us. We'd even be happy if we knew of certain Android devices that are supported as we have a certain amount of control over the deployment devices . . . if anyone does know of any Android handsets where continuous focus using ActionScript is supported on the read camera I'd love to know!

iBr3nt
Inspiring
March 7, 2012

Hi,

Have you tried setting the following tag in your -app.xml file?

Within the <android> <manisfestAdditions> tag:

<uses-feature android:name="android.hardware.camera.autofocus"/>

In my app descriptor file I have that line right below the CAMERA permission tag.

iBrent

Inspiring
March 8, 2012

I have tried the app descriptors and all that but it still didn't work. On my bug request page, the Adobe guy kept saying that the Android phone I had didn't support "continuous autofocus" although I think it does since the iPhone one does work as expected.

Participant
October 3, 2011

Same problem.  Android HTC Desire.  Unfortunately setMode blanks the screen while it does it's thing...

Participating Frequently
March 7, 2012

Is anyone still looking at this? I read the self closed bug report that was raised and it didn't seem to make any sense based on what I'm seeing.

I am using the Camera class on Android to view the live stream using a Samsung Galaxy S2. The focus received at the point of calling setMode is retained throughout the life of the application. If I call setMode again, as others have reported, the focus will update but with an unacceptable lag.

Now, I know that people keep referring to continuous auto-focus and whether or not a particular device supports it, if I use the CameraUI class, that does continuously autofocus, so I'm assuming my device does support it.

Is there a reason that CameraUI and Camera respond differently? Is there a way I can capture the stream from CameraUI if so?

Inspiring
March 7, 2012

Hello, I sadly did not close the bug report, the Adobe guys did. I still have not figured out how to solve the problem in Adobe AIR; the guy never got back to me with the information I needed.

The thing I understand as far as CameraUI vs Camera goes is that one uses the native api of the device while the other reacts similar to a webcam in Flash. I don't think you can capture anything from CameraUI (they have to actually take the photos, I believe) so that wasn't a solution. My team ended up just implementing everything in PhoneGap and got a super fast QR scanner (given the ZXing library).

Participant
September 22, 2011

Hi, are there some news about that topic or did you find a work arround yet? I have the same problem and i can't find a solution except for calling a endless time the setMode method which is really dirty and the performance sucks...

Regards Valentin

Participating Frequently
September 22, 2011

Hi Valentin,

As far as I’m aware there’s no solution for this as of yet. I’m hoping it gets fixed in a later release.

To workaround the issue I’ve added a ‘focus’ button click handler that calls setMode on the camera object rather than calling it periodically. Repeatedly calling setmode was too painful in terms of performance as you point out. Interestingly I only have the issue with Android devices, seems to not be an issue on iPhone.

If I do find a solution in the mean time I will let you know.

Hope this helps…

Regards,

Scott.

Participant
September 22, 2011

Hi Scott,

thats similar to my temporary solution.

I hope Adobe will take care of this problem soon.

Thank you for your ideas.

Regards Valentin

Participating Frequently
June 30, 2011

The focus is dependent on the system camera hardware/software. If the camera doesn't support continuous autofocus, then AIR triggers the focus when you call setMode() and when you attach to a NetStream. You could try reattaching the Netstream to trigger the autofocus instead of setMode. If that isn't faster, I don't know what you could do.

Inspiring
June 30, 2011

Thanks for the reply. The problem is, though, the camera does do continuous focus when I'm using a native QR code scanner.

When I do

Video.attachCamera(null);

Video.attachCamera(Camera);

nothing seems to happen. Does the camera only refocus with Netstream.attachCamera?

Participating Frequently
July 2, 2011

Autofocus is supposed to happen with Netastream.attachCamera(), but now that I think about it, that isn't appropriate for your use case.

Please file a bug at https://bugbase.adobe.com/ about continuos autofocus not working.

Thanks,

Joe