Enable/Disable Wifi on Android device

Hello,

I am trying to enable or disable Wifi from Unity on my Android device.
I tried to do the different things I found on the forum without success.

If I do:

using(var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
     string wifiServiceName = unityPlayer.Get<string>("WIFI_SERVICE");
     using(var wifiManager = unityPlayer.Call<AndroidJavaObject>("getSystemService", wifiServiceName))
     {
         wifiManager.Call("setWifiEnabled", false);
     }  }

I have an error saying that WIFI_SERVICE doesn’t exist.

If I do:

		using (AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity"))
		{
			using (var wifiManager = activity.Call<AndroidJavaObject>("getSystemService","wifi"))
			{
				wifiManager.Call<AndroidJavaObject>("setWifiEnabled", false);
			}	
		}

I have an error saying that setWifiEnabled is not a function, (nor a static function if I do CallStatic).

I have my manifest.xml correctly merged, I can check that I have all the permissions on the application manager.

I spent few hours trying to figure out how to do that and I am stuck!

Does anyone know a simple way to do so?

Thanks a lot for your help,

Benjamin

The answer is here
https://stackoverflow.com/questions/39111324/enable-disable-wifi-on-android-in-unity