I want to turn on or off mobile hotspot via code. I read many tutorials, but I see that it only works with API version lower 26. And I see the function
wifiManager.setWifiApEnabled
It uses for turning on or off mobile hotspot. But it is not existed in Api version higher. Is there any replace for it?
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = "Hotspot";
wifiConfiguration.preSharedKey = "Password123";
wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
// Enable hotspot
wifiManager.setWifiEnabled(false); // Disable Wi-Fi
wifiManager.setWifiApEnabled(wifiConfiguration, true); // setWifiApEnabled is not existed in api verion higher
I wonder why tasker app or macrodroid can turn on or turn off the hotspot.