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
}
希望這會很有用!
添加回答
舉報