//Função para verificar existência de conexão com a internet
public boolean verificaConexao() {
boolean conectado;
ConnectivityManager conectivtyManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (conectivtyManager.getActiveNetworkInfo() != null
&& conectivtyManager.getActiveNetworkInfo().isAvailable()
&& conectivtyManager.getActiveNetworkInfo().isConnected()) {
conectado = true;
} else {
conectado = false;
}
return conectado;
}
// Verifica a conexao
if (verificaConexao() == true){
// Chama a classe RequestTask
new RequestTask().execute(ok);
} else {
loader.setVisibility(View.GONE);
tx.setVisibility(View.VISIBLE);
tx.setText("Por favor, conecte-se a internet :(");
ba.setVisibility(View.VISIBLE);
}
I want to use this same condition in several places in my code. would I have to do something to call her instead of having to write her all over, every time I need her?