#Unity Android list wifi networks and sig...

1 messages · Page 1 of 1 (latest)

tight peak
#

Could you tell me more about this please? 😦 im not experienced with this topic and im little bit lost with how to add for example Wifi manager to unity. I was especially searching about it and i couldnt find it anything.

unborn frost
#

yup! one sec

#

look up AndroidJavaProxy objects. you'll want to inherit it. Create a class that holds an instance of this created object (we'll call it the main java comm class).

This allows you to implement essentially a shared class between C# and java (you'll also have to implement this in java) - then in your "main java comm class" you can link the two objects

#
public class MainAndroidCommClass
{

    Thread mainAndroidThread;

    AndroidJavaObject jMainActivity;
    AndroidJavaObject publicApiInstance;
    public UnityJavaCallbackHandler unityJavaCallbackHandler;

    public MainAndroidCommClass() // our main java comm class constructor
    {
        UnityJavaCallbackHandler = new MyAndroidJavaProxyClass()
        ...
        // requires making a new thread to share with java stuff:
        mainAndroidThread = new Thread(UnityAndroidStartThread);
        mainAndroidThread.Start();
    }
    
    void UnityAndroidStartThread()
    {
        AndroidJNI.AttachCurrentThread();

        UnityEngine.Debug.Log("LAUNCHING NEW JAVA OBJECT IN NEW THREAD.");
        jMainActivity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
        
        // CreateMyJavaObject is a function in MyJavaObject for initializing things
        // and we pass the instance of our UnityJavaCallbackHandler
        publicApiInstance = new AndroidJavaClass(
            "com.mycompany.mypackagenameinjava.MyJavaObject").CallStatic<AndroidJavaObject>("CreateMyJavaObject", jMainActivity, unityJavaCallbackHandler); 
    }
    ...

in java:

public class MyJavaObject
{
    // unity comm callback would be your java version of UnityJavaCallbackHandler
    public static MyJavaObject CreateMyJavaObject(Context context, IUnityCommCallback callback)
    {
        MyLogger.info(MyLoggingTag, "Java class starting");
        return new MyJavaObject(context, callback);
    }
    ... rest of your java code
    
}
#

This is a rough example without the implementation of the shared callback object... I recommended checking out documentation on this to get it running