Android’s Camera.Parameters.setFocusAreas with Nexus 4

Camera.Parameters.setFocusAreas seemed to be a very interesting piece of software.

It’s a function available for developers since Android API 14 (Android versions 4.0 and above), that should let an app a way to set the camera auto focus capability to point to any desired point of the available camera view.

Anyway, at least with a Nexus 4, I haven’t been able to make it work: Camera.Parameters.getMaxNumFocusAreas() returns 1, which is good (any number >0 is necessary in order for setFocusAreas to be available), but although then one can set setFocusAreas to an Area, the camera seems to ignore any Area value, and continues to focus using just the very centre of the view.

I’m disappointed.

There’re more complaints related to this issue:

Another curiosity: a call to getFocusAreas() before calling to setFocusAreas provokes a funny Exception:

java.lang.NumberFormatException: Invalid int: ” 0″
at java.lang.Integer.invalidInt(
at java.lang.Integer.parse(
at java.lang.Integer.parseInt(
at java.lang.Integer.parseInt(
at android.hardware.Camera$Parameters.splitInt(
at android.hardware.Camera$Parameters.splitArea(
at android.hardware.Camera$Parameters.getFocusAreas(

I think I can swear I have no ” 0″ (space + zero) as a String value for zero on my code.



2 thoughts on “Android’s Camera.Parameters.setFocusAreas with Nexus 4

  1. I tested setFocusAreas() & autoFocus() on Nexus4 and confirmed these functions work correctly. Would try again?
    Calling getFocusAreas() in the initial state of preview, it produces error.
    But, after calling setFocusAreas(), it works fine.

    • Hi Sunkyoo,
      The functions seems to work; my problem is that the hardware does not seem to obey them: the camera do not correctly focus the area established with setFocusAreas(). After some testing, the problem seem to be in the hardware itself: Nexus 4 camera have a strange focus behavior even with its own autofocus: near objects do not seem to get correctly focused if they occupy small areas of the focus view. Dunno also if android version is important: in my case it’s 4.2.2. Have you been able to instruct setFocusAreas() to an area and obtain a focused picture of a near (~10-20cm) object there?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s