Do you have any idea how to establish a wifi connection with sending password in my android application?
Give your ssid and password
fun connectToWifi(ssid: String, password: String) {
val connManager = context!!.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
val wifiConfiguration = WifiConfiguration()
wifiConfiguration.SSID = String.format("\"%s\"", ssid)
wifiConfiguration.preSharedKey = String.format("\"%s\"", password)
wifiManager = context!!.getSystemService(Context.WIFI_SERVICE) as WifiManager
val netId: Int = wifiManager.addNetwork(wifiConfiguration)
wifiManager.disconnect()
wifiManager.enableNetwork(netId, true)
wifiManager.reconnect()
val config = WifiConfiguration()
config.SSID == "\"\"" + ssid + "\"\""
config.preSharedKey == "\"\"" + password + "\"\""
wifiManager.addNetwork(config)
}