• 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 Key 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

Setting android tools location in unity 4 Answers

Cannot install apk in android 8.0.0 (API level 26) 0 Answers

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

AndroidJavaProxy no such method exception,AndroidJavaProxy no such proxy method error 1 Answer

Unity Android setup question 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges