• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Greenie · Aug 22, 2014 at 02:23 PM · androidcameraiosmobile

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jokim · Aug 22, 2014 at 04:32 PM 0
Share

Also important to note, not all phones actually have autofocus available.

avatar image XFaure · Sep 05, 2014 at 02:39 PM 0
Share

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

avatar image Landern · Sep 05, 2014 at 02:42 PM 0
Share

There's documentation(Building plugins for android) for that.

Native = Java code being called from unity.

avatar image XFaure · Sep 05, 2014 at 05:37 PM 0
Share

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;

avatar image HamFar XFaure · Jun 09, 2017 at 02:48 PM 0
Share

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

avatar image rprrs HamFar · Jul 10, 2017 at 12:42 AM 0
Share

Hello Hamfar, do you found a solution of this? Appreciate a lot that you could help me

Show more comments
avatar image
0

Answer by HamFar · Jul 13, 2017 at 06:40 AM

@rprrs I have written an adroind plug-in for unity3d, but for some reason it does not work. I am happy to share my code if anyone is interested. Perhaps you can go through it and see if you can get it to work?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Antialiasing on iOS 1 Answer

launch mobile games Unity 4.6 need unity pro IOS and Android? And Unity Android or IOS needs some library´s to work? 1 Answer

Button as a child of a button 0 Answers

In what resolution should design my mobile game? 1 Answer

Bake Substance for Mobile 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges