Code example for NetworkInfo

Methods: getDetailedState, getReason, isConnected, toString

0
			//thats the correct action, now check if the connectivity is broken 
			ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
			//NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); 
			NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
			 
			if (activeNetworkInfo != null && activeNetworkInfo.getReason() == null) {
				return; 
			} 
			 
			Log.v(TAG, "Connectivity change");
			 
			if (activeNetworkInfo == null || !activeNetworkInfo.isConnected())
			{ 
				//disconnected 
				mConnected=false;				
			} else { 
				//connected, test if we did failover from mobile 
				mConnected=true;
				 
				if (connectScheduled) {
					connectScheduled = false;
					mXMPPRemoteService.connect();
				} else { 
//				if (intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false)) 
					mXMPPRemoteService.reconnect();
				} 
				 
			} 
			 
			if (activeNetworkInfo != null) {
				Log.v(TAG,activeNetworkInfo.toString());
				Log.v(TAG,activeNetworkInfo.getDetailedState().toString());
			} 
			Log.v(TAG,"isfailover: "+intent.getExtras().getBoolean(ConnectivityManager.EXTRA_IS_FAILOVER));
			if (intent.getExtras().getParcelable(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO)!=null)
				Log.v(TAG,"oni: "+intent.getExtras().getParcelable(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO).toString());
		}