Android wifimanager sempre retorna true
Isto está me matando e qualquer ajuda seria muito apreciada.
Eu quero me conectar a uma rede aberta usando o gerenciador de wifi. O problema que estou enfrentando é que o código reivindica conexão com qualquer rede - mesmo as não existentes. Abaixo está o código inteiro que é executado e chamado com o SSID de uma rede. Não importa qual sequência de caracteres você passa para ela como o SSID de uma rede, mesmo que essa rede não exista em nenhum formato ou forma, as declarações enableNetwork retornam true, o que eu acredito que significa que ela está conectada à rede.
O que eu preciso fazer é garantir que eu tenha uma conexão. Portanto, se eu passar um SSID de rede que não existe (por exemplo, está fora do alcance), a API retornará uma falha ao tentar conectar-s
Todas as idéias / sugestões / sugestões serão muito apreciada
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;
}