- Home /
AndroidJava and setting a BitSet value
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.
using (AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity"))
{
try
{
using (var WifiSetup = activity.Call<AndroidJavaObject>("getSystemService", "wifi"))
{
AndroidJavaObject newConnection = new AndroidJavaObject("android.net.wifi.WifiConfiguration");
newConnection.Set<string>("SSID", mSSID);
newConnection.Set<string>("preSharedKey", mPWD);
newConnection.Set<bool>("hiddenSSID", false);
//THOSE UP HERE WORK!
//DOESN'T WORKS LIKE THIS:
newConnection.Set<int>("allowedAuthAlgorithms", 0);
//DOESN'T WORKS EVEN LIKE THIS (breaks at definition)
AndroidJavaObject OPEN = new AndroidJavaObject("android.net.wifi.WifiConfiguration.WifiConfiguration.AuthAlgorithm.OPEN");
newConnection.Set<AndroidJavaObject>("allowedAuthAlgorithms", OPEN);
//THIS DEFINITION WORKS
AndroidJavaObject allowedAuthAlgorithms = newConnection.Get<AndroidJavaObject>("allowedAuthAlgorithms");
//NEITHER THIS ONE WORKS
allowedAuthAlgorithms.Call<int>("set", "WifiConfiguration.AuthAlgorithm.OPEN");
//CODE CONTINUES THE REST IS WORKING AND TESTED
Answer by jschieck · Nov 17, 2018 at 04:55 PM
I know this is very old but if anyone in the future needs the answer to this, this is how you do it... specifically for an OPEN network.
using (var allowedKey = new AndroidJavaObject("java.util.BitSet"))
{
allowedKey.Call("set", 0);
wifiConfig.Set("allowedKeyManagement", allowedKey);
}
Right, next time just check the documentation. BitSet in Java is a class and therefore you can't just set it to an integer. Also the BitSet class can represent a set of bits of arbitrary size. It seems to use an array of bytes internally.
also note that allowed$$anonymous$$ey.Call("set", 0);
will just set the bit at index 0 and the rest stays unchanged, If you want to clear all bits (setting all bits to 0) you may want to use the clear method ins$$anonymous$$d.
I've never used the wifi configuration class but i would guess you don't have to create a BitSet yourself. You probably can just manipulate the existing instance. Though i could be wrong about that
Your answer
Follow this Question
Related Questions
How to convert Dictionary to Java HashMap 0 Answers
CreateJavaRuntime problem 0 Answers
Throw object in android 1 Answer
What is the difference between AndroidJavaClass.Call and AndroidJavaObject.Call 2 Answers
Duplication Problem. Please help. 2 Answers