1 回答

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊
經(jīng)過(guò)一些實(shí)驗(yàn)后,我發(fā)現(xiàn)當(dāng)與 hospot 的連接丟失時(shí),wifiInfo 不會(huì)更新,因此要修復(fù)它,您可以使用
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
}
希望這會(huì)很有用!
添加回答
舉報(bào)