Hi all I need to verify if my device is currently connected to internet or not and so I wrote this class that uses a ConnectivityManager to check:
public boolean checkInternetConnection() {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isAvailable() && cm.getActiveNetworkInfo().isConnected()) {
return true;
} else {
return false;
}
}
works great, because right now the method is in a class in the main package (com.App), but how should I change the code to make it work in a class defined in com.App.Utility ?
Thanks!
1 Answer