I’m trying to check if a simple connection is available on my honeycomb app. I’ve tried 2 different versions of the function:
public boolean networkAvailable() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo().isConnectedOrConnecting();
}
and
private boolean networkAvailable(){
ConnectivityManager connectionManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = connectionManager.getActiveNetworkInfo();
return activeNetwork != null;
}
Neither of these work on my Honeycomb tablet though, they crash wherever I try to call them. Is there a particular way of doing this on 3.2 or…what am I missing?
This should work. You can even differentiate the type of network available. Make sure you have the following permissions declared in the manifest.