Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 Pivetta · Feb 28, 2017 at 07:41 AM · androidobjecttypejava to c#jni

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

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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);
 }

Comment
Add comment · Show 1 · 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
avatar image Bunny83 · Nov 17, 2018 at 06:52 PM 0
Share

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

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges