Code example for ConnectivityManager: Querying Network Reachability

Methods: getActiveNetworkInfo

0
	} 
 
	@Override 
	public boolean isWifiConnected() { 
		ConnectivityManager mgr =  (ConnectivityManager) app.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo ni = mgr.getActiveNetworkInfo();
		return ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI;
	} 
 
	@Override 
	public boolean isInternetConnected() { 
		ConnectivityManager mgr = (ConnectivityManager) app.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo active = mgr.getActiveNetworkInfo();
		if(active == null){
			return false; 
		} else { 
			NetworkInfo.State state = active.getState();
			return state != NetworkInfo.State.DISCONNECTED && state != NetworkInfo.State.DISCONNECTING;
		} 
	}