Code example for NetworkInfo.State

Methods: equals

0
	public static int getAvailableNetworkType(Context context) {
		ConnectivityManager cm = (ConnectivityManager) 
				context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo ni;
		ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
		if (ni != null && State.CONNECTED.equals(ni.getState()))
			return ConnectivityManager.TYPE_WIFI;
		ni = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
		if (ni != null && State.CONNECTED.equals(ni.getState()))
			return ConnectivityManager.TYPE_MOBILE;
		return -1; 
	} 
} 
Experience pair programming with AI  Get Codota for Java