Are you missing NullPointerException?
I am using the following method:
public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
try {
return cm.getActiveNetworkInfo().isConnectedOrConnecting();
} catch(NullPointerException n) {
return false;
}
}