Code example for ConnectivityManager: Querying Network Reachability

Methods: getActiveNetworkInfogetNetworkInfo

	private ConnectivityManager connectivityManager;
	public boolean isConnected() { 
		final NetworkInfo ni = connectivityManager.getActiveNetworkInfo();
		if (ni == null) {
			//sometime when wifi is connecting, ni is null so check wifi explicitly 
			final NetworkInfo wifiConnectivityInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
			if (wifiConnectivityInfo.isConnected() || wifiConnectivityInfo.isConnectedOrConnecting()) {
				return true; 
			return true; 
		} else { 
			final State state = ni.getState();
			if (state.equals(State.CONNECTED) || state.equals(State.CONNECTING)) {
				return true; 
Connect your IDE to all the code out there  Get Codota for Java