How to call an enum from AndroidJavaObject

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.

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.

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.
1 Like