Enable Wifi from my app

I know regular Android rules (unfortunately) restricted apps from being able to toggle the Wifi state as stated here. But I found in Samsung, under Special Access, the option “Wi-Fi control”. There, my app can be allowed to control wifi. It says “Allow this app to turn Wi-Fi on or off…”
I did that but I am not able to turn Wi-Fi on or off. I tried with this code:

WifiManager mWifiManager = (WifiManager) myContext.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
mWifiManager .setWifiEnabled(true or false);

But it does nothing. Wifi is not turned on or off. Any help on this?
Thanks

Hi,
As far as I know, to turn on/off wifi from application, your application needs to be on foreground and screen should be on.
More for turn on/off wifi you can check the code:

Hi Antonio,

As you can read in this joined article:

The method setWifiEnabled was deprecated in API level 29 and so apps will not be able to turn Wi-Fi OFF/ON anymore from Android-10 API level 29 until google provides an alternative solution.

Regards,