Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to call an enum from AndroidJavaObject

Discussion in 'Android' started by kittik, Jun 3, 2021.

  1. kittik

    kittik

    Joined:
    Mar 6, 2015
    Posts:
    565
    I am trying to check an enum, SupplicantState in an AndroidJavaObject. I do not often do Android development and am not sure know how to get the state.

    Code (CSharp):
    1. if(wifiInfo.Call<SupplicantState>("getSupplicantState") == wifiInfo.Call<Enum<SupplicantState>>("SupplicantState.COMPLETED")
    I'd appreciate any direction towards getting this to compile and manage to ascertain the state. Thanks.
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    In Java enums are classes and their values are static fields in those classes.
    So it should be like this:
    - Use AndroidJavaClass for SupplicantState
    - Get static field COMPLETED (as AndroidJavaObject)
    - Call GetRawObject() on both values and compare them using AndroidJNI.IsSameObject(); or you Call Java method "equals" on one of them passing other as argument.
     
    studentutu likes this.