Code example for NetworkInfo

Methods: getStateisConnectedOrConnecting

0
 
	public static boolean checkNetworkConnectivity(final Activity activity) {
		ConnectivityManager cm = (ConnectivityManager) activity
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo netInfo = cm.getActiveNetworkInfo();
		if (netInfo != null && netInfo.isConnectedOrConnecting()) {
			return true; 
		} else if (netInfo != null
				&& (netInfo.getState() == NetworkInfo.State.DISCONNECTED
						|| netInfo.getState() == NetworkInfo.State.DISCONNECTING
						|| netInfo.getState() == NetworkInfo.State.SUSPENDED || netInfo
						.getState() == NetworkInfo.State.UNKNOWN)) {
			return false; 
		} else { 
			return false; 
		} 
	} 
 
	public static void showNetworkConectivityAlert(final Activity activity) {
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);
Stop searching for code, let great code find you!  Add Codota to your java IDE