Search Unity

AndroidJava and setting a BitSet value

Discussion in 'Android' started by Pivetta, Feb 27, 2017.

  1. Pivetta

    Pivetta

    Joined:
    Oct 11, 2013
    Posts:
    19
    Hi I am in a struggle at assigning a BitSet value in a Android Java Object I'm referencing.

    I tried with Int, or even to copy the referred value into a AndroidJavaObjects and now I am short of Ideas.

    Here is part of my code, I am making a HotSpot manager inside the game itself. I'm debugging with logcat and I am putting a Debug.Log every row to see where the code stops

    What I need is to assign AuthAlgorithm to OPEN, without having the BitSet type in C#

    Thanks in advance.

    (I know the code isn't writed right, I just stacked all my tries one over the other)

    1. using (AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity"))
    2. {
    3. try
    4. {
    5. using (var WifiSetup = activity.Call<AndroidJavaObject>("getSystemService", "wifi"))
    6. {
    7. AndroidJavaObject newConnection = new AndroidJavaObject("android.net.wifi.WifiConfiguration");
    8. newConnection.Set<string>("SSID", mSSID);
    9. newConnection.Set<string>("preSharedKey", mPWD);
    10. newConnection.Set<bool>("hiddenSSID", false);
    11. //THOSE UP HERE WORK!
    12. //DOESN'T WORKS LIKE THIS:
    13. newConnection.Set<int>("allowedAuthAlgorithms", 0);
    14. //DOESN'T WORKS EVEN LIKE THIS (breaks at definition)
    15. AndroidJavaObject OPEN = new AndroidJavaObject("android.net.wifi.WifiConfiguration.WifiConfiguration.AuthAlgorithm.OPEN");
    16. newConnection.Set<AndroidJavaObject>("allowedAuthAlgorithms", OPEN);
    17. //THIS DEFINITION WORKS
    18. AndroidJavaObject allowedAuthAlgorithms = newConnection.Get<AndroidJavaObject>("allowedAuthAlgorithms");
    19. //NEITHER THIS ONE WORKS
    20. allowedAuthAlgorithms.Call<int>("set", "WifiConfiguration.AuthAlgorithm.OPEN");
    //CODE CONTINUES THE REST IS WORKING AND TESTED

    I wrote also on Unity Answer, but I feel here is where the right people are
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    You can simplify things by defining a new Java method that accepts an int, internally (in Java) it will convert it into the proper enum and set it on the relevant object.

    This way, you don't have to deal with complex object types from C# --> Java