Skip navigation
jthereliable
Currently Being Moderated

Camera autofocus on Android

Jun 29, 2011 4:34 PM

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.)

 
Replies
  • Currently Being Moderated
    Jun 30, 2011 10:09 AM   in reply to jthereliable

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 2, 2011 9:51 AM   in reply to jthereliable

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 18, 2011 4:07 AM   in reply to Joe ... Ward

    I'm also having the same problem with the Android HTC Desire HD

    in that camera focus only occurs after a call to camera.setmode()

     

    Did this ever get raised as a bug?

     

    Note: Autofocus appears to work fine on the iPhone 3GS using the raw camera.

     

    Thanks,

    Scott.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 18, 2011 7:10 AM   in reply to jthereliable

    In the absence of a bug, I logged one myself (although only mentioned HTC Desire HD)

     

    https://bugs.adobe.com/jira/browse/SDK-30820

     

    Regards,

    Scott.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 22, 2011 1:26 AM   in reply to jthereliable

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 22, 2011 1:37 AM   in reply to Valdur55

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 22, 2011 1:58 AM   in reply to scott.robinson

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 2, 2011 9:52 PM   in reply to jthereliable

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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 7, 2012 3:06 AM   in reply to Anthony Artmann

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 7, 2012 8:45 AM   in reply to jthereliable

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 7, 2012 9:21 AM   in reply to jthereliable

    Bug https://bugs.adobe.com/jira/browse/SDK-30820 is still open i believe, although has no votes to date so will probably not get looked into.

     

    Vote up this is still an issue for you!

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 14, 2012 4:11 AM   in reply to iBr3nt

    Hi All,

     

    Can anyone confirm if they have actually seen continuous autofocus working on an Android device using the Flex SDK.

     

    I have added the following to my manifest file… (myproject-app.xml) as described in the Android documentation:

     

    <uses-permission android:name="android.permission.CAMERA" />

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

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

     

    And am accessing the raw camera using Camera.getCamera();

     

    I have so far tested on HTC Desire HD and Samsung Galaxy S2 without any joy, would be curious to know if this fails for all devices.

     

    Many Thanks,

    Scott.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 1:27 AM   in reply to jthereliable

    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??

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 4:07 AM   in reply to jthereliable

    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!

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 25, 2012 4:03 AM   in reply to jthereliable

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 2, 2012 1:04 AM   in reply to MrCodeghost

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (1)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points