NetworkInfo getDetailedState - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for NetworkInfo getDetailedState method.

This code example shows how to use the following methods:getDetailedState
    public void getNetworkInfoShouldReturnAssignedValue() throws Exception { 
        NetworkInfo networkInfo = ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTING);
        shadowConnectivityManager.setNetworkInfo(ConnectivityManager.TYPE_WIFI, networkInfo);
        NetworkInfo actual = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        assertThat(actual).isSameAs(networkInfo);
        assertThat(actual.getDetailedState()).isEqualTo(NetworkInfo.DetailedState.CONNECTING);
    } 
 
    @Test 
    public void networkInfoShouldReturnFalseCorrectly() { 
        shadowOfActiveNetworkInfo.setConnectionStatus(false);
 
        assertFalse(connectivityManager.getActiveNetworkInfo().isConnectedOrConnecting());
        assertFalse(connectivityManager.getActiveNetworkInfo().isConnected());
    } 
 
    @Test 
    public void networkInfoShouldReturnTypeCorrectly(){ 
    	shadowOfActiveNetworkInfo.setConnectionType(ConnectivityManager.TYPE_MOBILE);
    	assertEquals(ConnectivityManager.TYPE_MOBILE, shadowOfActiveNetworkInfo.getType());
7
CodeRank
This code example shows how to use the following methods:getDetailedState, isConnected
                            intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE))); 
                } 
            } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { 
                NetworkInfo info = (NetworkInfo) intent.getParcelableExtra( 
                        WifiManager.EXTRA_NETWORK_INFO); 
                mConnected.set(info.isConnected()); 
                handleStateChanged(info.getDetailedState()); 
            } 
        } 
    }; 
 
    public WifiEnabler(Context context, Switch switch_) {
        mContext = context;
        mSwitch = switch_;
 
        mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        mIntentFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
        // The order matters! We really should not depend on this. :( 
        mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
        mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
7
CodeRank
This code example shows how to use the following methods:getDetailedState
      } 
    } 
  } 
 
  private void handleNetworkStateChanged(NetworkInfo networkInfo) {
    NetworkInfo.DetailedState state = networkInfo.getDetailedState();
    if (state == NetworkInfo.DetailedState.FAILED){
      Log.d(TAG, "Detailed Network state failed");
      parent.gotError();
    } 
  } 
 
  private void handleChange(SupplicantState state, boolean hasError) {
    if (hasError || state == SupplicantState.INACTIVE){
      Log.d(TAG, "Found an error");
      parent.gotError();
    } 
  } 
} 
6
CodeRank
This code example shows how to use the following methods:getDetailedState, getReason, isConnected, toString
			//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) {

6
CodeRank
This code example shows how to use the following methods:getDetailedState, getState, getTypeName, isAvailable, isConnected
6
CodeRank
This code example shows how to use the following methods:getDetailedState, getExtraInfo, getReason, isAvailable, isConnected
        boolean isFailover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false);
 
        NetworkInfo currentNetworkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
        NetworkInfo otherNetworkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);
 
        if(currentNetworkInfo.isConnected() )
        { 
        	Log.v(TAG, "ON > "+ currentNetworkInfo.getReason() + " < Extra info > "+ currentNetworkInfo.getExtraInfo()  + " < STATE > " + currentNetworkInfo.getDetailedState() + " < AVAILABLE? > " + currentNetworkInfo.isAvailable() );
         
        	// getting the id of the freeWifi  
        	SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext() );
        	Integer freeWifiNetworkID = sharedPrefs.getInt("freeWifiNetworkID", 0);
    		Boolean networkAutoForget = sharedPrefs.getBoolean("auto_forget", false);
    		Boolean networkAutoLogin = sharedPrefs.getBoolean("auto_login", true);
        	 
        	// the "reasons" of the connection 
        	String connectionReason = currentNetworkInfo.getReason();
        	String connectionNetworkName = currentNetworkInfo.getExtraInfo(); 
        	 
        	// if it connects to FreeWifi stores the wifiID 

6
CodeRank
This code example shows how to use the following methods:getDetailedState, isConnected
                            intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE)));
                } 
            } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
                NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
                        WifiManager.EXTRA_NETWORK_INFO);
                mConnected.set(info.isConnected());
                handleStateChanged(info.getDetailedState());
            } 
        } 
    private void handleStateChanged(@SuppressWarnings("unused") NetworkInfo.DetailedState state) {
    } 
 
    private void handleWifiStateChanged(int state) {
        switch (state) {
            case WifiManager.WIFI_STATE_ENABLING:
                mCheckBox.setEnabled(false);
                break; 
            case WifiManager.WIFI_STATE_ENABLED:
                setSwitchChecked(true); 
                mCheckBox.setEnabled(true);
5
CodeRank
This code example shows how to use the following methods:getDetailedState
    } 
 
    private void handleNetworkStateChanged(NetworkInfo networkInfo) {
        if (mWifiManager.isWifiEnabled()) {
            String summary = Summary.get(this, mWifiManager.getConnectionInfo().getSSID(),
                    networkInfo.getDetailedState());
            mNetworkState.setText(summary);
        } 
    } 
 
    private final void updatePingState() { 
        final Handler handler = new Handler();
        // Set all to unknown since the threads will take a few secs to update. 
        mPingIpAddrResult = getResources().getString(R.string.radioInfo_unknown);
        mPingHostnameResult = getResources().getString(R.string.radioInfo_unknown);
        mHttpClientTestResult = getResources().getString(R.string.radioInfo_unknown);
 
        mPingIpAddr.setText(mPingIpAddrResult);
        mPingHostname.setText(mPingHostnameResult);
        mHttpClientTest.setText(mHttpClientTestResult);
5
CodeRank
This code example shows how to use the following methods:getDetailedState
		Log.v("LoginUSPNet", "Action: " + action);
 
		if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
			NetworkInfo info = (NetworkInfo) intent
					.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
			if (info.getDetailedState() == DetailedState.CONNECTED) {
				Log.v("LoginUSPNet", "Conectado");
 
				WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
				WifiInfo wifiInfo = wifiManager.getConnectionInfo();
				if (wifiInfo.getSSID().toUpperCase().contains("USP")) {
					Log.d("LoginUSPNet", "Rede USPNet detectada.");
					new loginThread().execute("USP"); 
				} else if (wifiInfo.getSSID().toUpperCase().contains("ICMC")) {
					Log.d("LoginUSPNet", "Rede ICMC detectada.");
					new loginThread().execute("ICMC");					 
				} 
			} 
 
		} 
4
CodeRank
This code example shows how to use the following methods:getDetailedState
			} 
		} 
	} 
 
	private void handleNetworkStateChanged(NetworkInfo networkInfo) {
		NetworkInfo.DetailedState state = networkInfo.getDetailedState();
		if (state == NetworkInfo.DetailedState.FAILED) {
			Log.d(TAG, "Detailed Network state failed");
			parent.gotError();
		} 
	} 
 
	private void handleChange(SupplicantState state, boolean hasError) {
		if (hasError || state == SupplicantState.INACTIVE) {
			Log.d(TAG, "Found an error");
			parent.gotError();
		} 
	} 
} 
4
CodeRank

Related NetworkInfo getDetailedState Questions & Answers:

getDetailedState Method Overview
Reports the current fine-grained state of the network.
See Code Examples for other Android NetworkInfo Methods: