- Home /
Phone camera autofocus
Hey there
Making a phone app that makes use of the camera on the back of the phone. However at the moment i'm having issues with focus. Does anyone know the javascript method of doing this.
Thanks in advance
Answer by tanoshimi · Aug 22, 2014 at 02:32 PM
There is no way to control the focus of a hardware camera through Unity. You might be able to do it with a native plugin (see, for example, Android's FOCUS_MODE
and FOCUS_DISTANCE
parameters - http://developer.android.com/reference/android/hardware/Camera.Parameters.html), but this would obviously be device-specific.
Also important to note, not all phones actually have autofocus available.
I am also interested in setting the auto focus of the android camera, but can't figure out how to do it. I know how to do it if I were developing a native application with the Android Studio, but not with Unity...
Could you elaborate on what you mean by "native plugin" ?
Thank you
There's documentation(Building plugins for android) for that.
Native = Java code being called from unity.
Thank you for the hint.
However, I find this a bit strange to have to go into all this just to do something rather simple. Isn't there a way to recover the camera with the AndroidJavaClass/AndroiJavaObject once we have the UnityPlayerNativeActivity ? (In C#)
var jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
Something in this spirit :
var camera = jo.CallStatic<AndroidJavaObject>("getCamera", 0);
Except this does not work, it throws the following error :
AndroidJavaException: java.lang.NoSuch$$anonymous$$ethodError: no static method with name='getCamera' signature='(I)Ljava/lang/Object;' in class Lcom/unity3d/player/UnityPlayerNativeActivity;
Hi, Have you found an answer to this? I am working with a Unity3D app (C#) that scans a serial-number to recognise its characters (OCR) but it seems that the Android device's camera does not auto-focus, therefore the scanning (character recognition) is really bad. Can you help me; e.g. what code to go where in my C# Unity scripts, etc...? Thanks
Hello Hamfar, do you found a solution of this? Appreciate a lot that you could help me
Your answer
Follow this Question
Related Questions
Texture Quality - Performance for Mobile Devices 2 Answers
Raycast from player to touch point? 2 Answers
Mobile Keyboards -- Highlighting all text by default when keyboard is opened (iOS vs. Android) 0 Answers
Using the Volume Control Buttons On Mobile Devices 0 Answers
Does receipt verification require an internet connection? 0 Answers