以编程方式获取已连接的Wifi密码? [英] Programmatically get connected Wifi password?

查看:206
本文介绍了以编程方式获取已连接的Wifi密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要与Sony Wifi相机进行通信.用户指定相机的Wifi SSID和密码,该应用程序会连接,拍照并检索到android设备.当应用程序完成拍照后,我希望它恢复应用程序启动之前存在的Wifi连接(如果有).例如.用户在启动wifi摄像头应用程序时可能已连接到咖啡店热点,因此该应用程序应在完成后自动重新连接到该热点.

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.

要恢复先前存在的连接,我认为该应用需要知道SSID-以及密码.应用程序很容易确定预先存在的SSID-只需在切换到相机Wifi SSID之前调用WifiManager.getConnectionInfo().getSSID()即可.但是,如何获取预先存在的密码?我不想要求用户重新输入该密码.可以使用此功能吗?

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?

谢谢, 汤姆

推荐答案

您可以使用 WifiManager.enableNetwork API并传递您之前缓存的网络ID.

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.

这篇关于以编程方式获取已连接的Wifi密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆