Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
0
Question by CGinSeattle · Oct 28, 2017 at 07:20 PM · androidandroid sdkandroid-sdkandroidjavaobject

Unity to Android: passing CameraCharacteristics.Key values from Unity to Android cameraCharacteristics.get?

I'm trying to use the camera2 api from my Unity app via the safe (but slow, I know) AndroidJavaObject method.

I've worked out how to get to the camera manager, and how to get to the camera characteristics object/class, but to use the functionality you have to pass a Key, namely a CameraCharacteristics.NAME OF KEY HERE...

I learned that you can use $ on the end when trying to get classes that are enums, but that doesn't seem to work here. I'd rather not try to just fudge it and pass some int value that I scrounge up from the java source (if it's even possible to get that value), because for one thing, I'm not sure that would even work since the java side is expecting a CameraCharacteristics.Key

Does anyone have any ideas how to pass something like this?

Thanks,

Cynthia

 //camera2 (21+ version) class retrieval method (first get unity activity, as currentactivity, then...
 AndroidJavaObject camera2Mgr = currentActivity.Call<AndroidJavaObject>("getSystemService", "camera");

 if (camera2Mgr != null) { //use try catch instead, but for testing, check nullity
         
 //get cameracharacteristics on chosen camera device (id) using the manager 
 //camera id already chosen earlier and passed in as parameter
 String[] cameraList = camera2Mgr.Call<String[]>("getCameraIdList");
     
 AndroidJavaObject cameraCharacteristics = camera2Mgr.Call<AndroidJavaObject>("getCameraCharacteristics", cameraList[0]); //cameraId);

 // now need to call...        cameraCharacteristics.Call<float[]>("get", 
 CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL); 
 //how do I pass this key?
 //tried creating the key as a class, with both $KEY and $INFO_SUPPORTED_HARDWARE_LEVEL
 //but get class not found exception...so that doesn't seem to be the way to get at the right key needed

 AndroidJavaClass cchl = new AndroidJavaClass("android.hardware.camera2.CameraCharacteristics$KEY");

Comment
Add comment · Show 1
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 CGinSeattle · Oct 30, 2017 at 09:08 PM 0
Share

Still interested if anyone has found a way to do this. I tried every combo I could think of, but you must pass a $$anonymous$$ey to the call. And no, you can't just getstatic on the fields (the keys), since the class apparently has disallowed that (nosuchfield error).

The workaround I'm using is writing some Java (pure class .JAR) methods of a custom class that takes the cameraCharacteristics as a parameter then makes the .get call. Only problem is that you have to put a try/catch at the Unity level in case of failure, since a no such field error on a key will happen at the cameraCharacteristics class level, not my class which only calls the .get on that class.

Yes, another option would be to put all the java code into a javaclass, so that the cameraCharacteristics class is obtained within my custom class. That might make the exception happen at the custom class level but then again, I haven't tried it, so it still might happen at the Unity JNI/Object level. I only include it as an idea to those that want to contain the entire set of java calls into their own class and avoid a lot of use of the AndroidJavaClass.

I want to do most things within C#, so that's why I'm keeping most of my code in C#. This code isn't called much, just setup info, so it doesn't really affect performance that much.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rpasquini · Feb 15, 2018 at 10:27 PM

I was able to get this to work in C#. Here's a sample:

 AndroidJavaObject key = cameraCharacteristics.GetStatic<AndroidJavaObject>("SENSOR_INFO_PHYSICAL_SIZE");
 AndroidJavaObject sizef = cameraCharacteristics.Call<AndroidJavaObject>("get", key);
 float height = sizef.Call<float>("getHeight");
 float width = sizef.Call<float>("getWidth");

Hope this helps!

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.

Follow this Question

Answers Answers and Comments

151 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 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 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 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 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 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 avatar image

Related Questions

I want to know how to access an external USB camera connected to my Android smartphone. 0 Answers

Unity can't detect SDK tools thougt I've installed them! 0 Answers

How to get Android 10 (API Level 29) 1 Answer

AndroidApiLevel30 ? 0 Answers

unity Exception:JNI:Init'd AndroidJavaObject with null prt! 0 Answers


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