亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

WifiInfo getSSID 斷開連接時返回最后一個 SSID

WifiInfo getSSID 斷開連接時返回最后一個 SSID

守候你守候我 2023-05-10 17:18:16
我創建了一個需要處理 WiFi 的應用程序。我有這段代碼this.wifiManager = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);String currentSSID = wifiManager.getConnectionInfo().getSSID();問題是當我已經連接到熱點時當前的 SSID 是有效的但是當我斷開連接時它返回最后一個熱點的 SSID 而不是像 or 之類的null東西equivalent。
查看完整描述

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

}

希望這會很有用!


查看完整回答
反對 回復 2023-05-10
  • 1 回答
  • 0 關注
  • 140 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號