Skip to content

Instantly share code, notes, and snippets.

@philipesteiff
Created February 26, 2013 14:06
Show Gist options
  • Save philipesteiff/5038627 to your computer and use it in GitHub Desktop.
Save philipesteiff/5038627 to your computer and use it in GitHub Desktop.
[Android] Verifica se existe conexão disponível, retornando TRUE caso haja. Obs: Funciona em smartphone e tablet.
public static boolean isNetworkConnected(Context context){
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo network = cm.getActiveNetworkInfo();
if(network != null){
return network.isAvailable();
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment