これは私を殺しているので、どんな助けも大歓迎です。
wifiマネージャーを使用してオープンネットワークに接続したい。私が抱えている問題は、コードが任意のネットワークへの接続を要求していることです。存在しないものであってもです。以下は、実行され、ネットワークの SSID で呼び出されるコード全体です。ネットワークの SSID としてどの文字列を渡すかは問題ではありません。そのようなネットワークがどのような形や形でも存在しない場合でも、enableNetwork クレームは true を返します。これは、ネットワークに接続されていることを意味すると私は信じています。
私がしなければならないことは、私が接続していることを確認することです。そのため、存在しないネットワーク SSID を渡した場合 (たとえば、範囲外である場合)、API は接続の試行時に失敗を返す必要があります。
アイデア/ヒント/提案は大歓迎です。
public boolean conto (String network){
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
List<WifiConfiguration> configs = null;
int inetId = -1;
// make sure there are no funny stuff in the config
configs = wifi.getConfiguredNetworks();
for (WifiConfiguration config : configs) {
wifi.removeNetwork(config.networkId);
Log.d("********", "Removed Network: SSID=[" + config.SSID + "] and ID=[" + config.networkId + "]");
}
// Now add the network
wifiConfiguration.SSID = "\"" + network + "\"";
wifiConfiguration.hiddenSSID = false;
//wifiConfiguration.priority = 1;
//wifiConfiguration.networkId = 999;
inetId = wifi.addNetwork(wifiConfiguration);
if(inetId < 0) {
Log.d("********", "Could Not Add Network......... [" + wifiConfiguration.SSID + "]");
}
else {
Log.d("********", "Added Network......... [" + wifiConfiguration.SSID + "]");
// Lets be paranoid and double check the config file
Log.d("********", " +++++++++++++++++++++++++ This is what I have in Config File");
configs = wifi.getConfiguredNetworks();
for (WifiConfiguration config : configs) {
Log.d("********", "In the Config file after add, SSID=[" + config.SSID + "], ID=[" + config.networkId + "]");
}
// Now Enable the network
boolean successConnected = wifi.enableNetwork(inetId, true);
//boolean successAssociated = wifi.reassociate(); This did not change the results
if(successConnected) {
Log.d("********", "Connected to......... [" + inetId + "]");
}
else {
Log.d("********", "Could Not Connect to......... [" + inetId + "]");
}
}
return false;
}