连接到wifi时,我总是得到最后一个wifiInfo
。例如,手机现在连接到wifi-a,然后我启动程序,手机连接到wifi-b,但我得到的是wifi-a wifiInfo
。我该如何解决?
谢谢
@Override
public void run() {
if (wifiConnectFlag == 0) {
Log.e(TAG, "connect wifi start...");
wifiAdmin = new WifiAdmin(getApplicationContext());
wifiAdmin.openWifi();
boolean b = wifiAdmin.disconnectWifi();
Log.d(TAG, "run: "+b);
WifiConfiguration wificon = wifiAdmin.CreateWifiInfo("MERCURY_954F4C", "", 1);
wifiAdmin.addNetwork(wificon);
wifiConnectFlag = 1;
Log.e(TAG, "connect successed");
String ssid = wifiAdmin.getSSID();
String bssid = wifiAdmin.getBSSID();
int id = wifiAdmin.getNetworkId();
String ipString = wifiAdmin.intToIp(wifiAdmin.getIPAddress());
Log.e("IP", "ip: "+ipString+" id: "+id+" ssid: "+ssid+" bssid: "+bssid);
//Log.e(TAG, String.valueOf(wifiAdmin.getIPAddress()));
}
}