1 回答
TA贡献1860条经验 获得超8个赞
经过一些实验后,我发现当与 hospot 的连接丢失时,wifiInfo 不会更新,因此要修复它,您可以使用
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean isConnected = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
this.wifiManager = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
String currentSSID = wifiManager.getConnectionInfo().getSSID();
/*
Surround your ssid with " when you compare it with the ssid of the wifimanager
because it will return your SSID surouded by quotes
*/
if(currentSSID.equals("\"" + your_net_ssid + "\"") && isConnected){
//You are realy connected to the hospot
}else{
//The connection dont exist
}
希望这会很有用!
添加回答
举报