Programmatically get connected Wifi password?

蹲街弑〆低调 提交于 2020-05-10 03:20:49

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/20847949/programmatically-get-connected-wifi-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!