Before requesting any requests, I'll make a connection test:
ConnectivityManager conexao;
private boolean verificaConexao() {
this.conexao = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = this.conexao.getActiveNetworkInfo();
if ((netInfo != null) && (netInfo.isConnectedOrConnecting()) && (netInfo.isAvailable())) {
Log.i("lgg", "conectado");
return true;
} else {
Log.i("lgg", "sem conexão");
return false;
}
}
I have 2 IP's of output, so I created a Switch
that I make the exchange, so I have 4 tests:
java.net.ConnectException: Failed to connect to /IP2
) IP 2, it really will not respond depending on the network the device is connected to.
I would like to know how to handle this error to return false
?