How can I detect that there was an error when connecting to a wifi?

0

In my application I ask you to connect to a Wi-Fi network, but there are times when the user puts the password wrong because we are human. I want that if this happens put a warning sign. Is there any way to know this? It must be because the operating system detects it. Some help? Thanks in advance.

    
asked by Alex Rivas 25.06.2018 в 15:03
source

1 answer

0

I was going to put this in a comment but it's too long for such, so I put it here:

Until API 28 there was an int called ERROR_AUTHENTICATING in class WifiManager , whose docs you can see here .

If you want the app to be compatible with the newer versions of android, you can use the class WifiInfo , which you can see here , and use a code such that this:

//Si asi da error de sintaxis, llama a esta funcion utilizando el contexto de la app
//Algo asi: WifiInfo redInfo = getBaseContext().getConnectionInfo();
WifiInfo redInfo = getConnectionInfo();
String WifiSSID = redInfo.getBSSID();
//Si el valor de WifiSSID es "<unknown ssid>" no está conectado/ha fallado la conexion
if(WifiSSID.equals("<unknown ssid>")) {
   //Hacer algo en base al error
} else {
   //No hay error, todo correcto
}

I would like to emphasize that, according to the docs WifiManager :

  

This class should only be obtained from the context of the application, not from another to avoid memory loss in the process that executes it.

    
answered by 25.06.2018 / 15:18
source