As an android developer who currently is working on an EMM client I want to silently connect device to wifi network. I have device owner privilege but still need to show user a prompt and wait for user acceptance.
Because I am device owner of a manged device, Is there any way of doing this? I couldn't find any related API in android device policy manager.
You can use the following line of code.
val wifiConfig = WifiConfiguration()
wifiConfig.SSID = String.format("\"%s\"", wifiName)
wifiConfig.preSharedKey = String.format("\"%s\"", wifiPassWord)
WifiConfigUtil.saveWifiConfiguration(context, wifiConfig)
It might show as deprecated but it's valid for EMM clients. Know this step will only save the wifi and the device will auto-connect to this network.