Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Detect if Wifi is enabled on Android without plugin

Discussion in 'Android' started by jbvobling, May 23, 2019.

  1. jbvobling

    jbvobling

    Joined:
    Sep 26, 2017
    Posts:
    27
    AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    AndroidJavaObject currentActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
    AndroidJavaClass contextClass = new AndroidJavaClass("android.content.Context");
    AndroidJavaObject context = currentActivity.Call<AndroidJavaObject>("getApplicationContext");

    string Context_WIFI_SERVICE = contextClass.GetStatic<string>("WIFI_SERVICE");
    AndroidJavaObject wifiService = context.Call<AndroidJavaObject>("getSystemService", Context_WIFI_SERVICE);
    bool test1 = wifiService.Call<bool>("isWifiEnabled");

    Anyone know what i'm doing wrong?
     
unityunity