Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically get connected Wifi password?

My app needs to communicate with a Sony Wifi camera. The user specifies the camera Wifi SSID and password, the app connects, takes a picture and retrieves it to the android device. When the app is done taking pictures, I want it to restore the Wifi connection (if any) that existed before the app was started. E.g. the user may have been connected to to a coffee shop hotspot when she starts the wifi camera app, and so the the app should automatically reconnect to the hotspot when it's done.

To restore the pre-existing connection, the app needs to know the SSID - and also the password, I think. It's easy for the app to determine the pre-existing SSID - just call WifiManager.getConnectionInfo().getSSID() before switching to the camera Wifi SSID. But how to get the pre-existing password? I don't want to require the user to re-enter that password. Is this functionality possible?

Thanks, Tom

like image 623
user604713 Avatar asked Dec 30 '13 21:12

user604713


1 Answers

You can use the WifiInfo.getNetworkId API to get current network id and save it for future use. When you want to connect back to original network use WifiManager.enableNetwork API and pass the network ID you cached before.

like image 189
vishalm Avatar answered Oct 10 '22 21:10

vishalm