NetworkInfo isConnected - 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 isConnected method.

This code example shows how to use the following methods:isConnected
 
		ConnectivityManager connectivityManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
		 
		boolean connected = (activeNetInfo != null) && (activeNetInfo.isConnected());
		 
		Logger.I(TAG, "LOGGER: Network status change, connected = " + String.valueOf(connected) );
		RhodesService.getInstance().notifyNetworkStatusChanged(connected?NETWORK_CONNECTED:NETWORK_DISCONNECTED);
	} 
} 
10
CodeRank
This code example shows how to use the following methods:isConnected
    { 
        boolean state = false;
        final ConnectivityManager conMgr =  (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
 
		final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
		if (activeNetwork != null && activeNetwork.isConnected()) {
			state = true;
		} else { 
			state = false;
		} 
 
        return state;
    } 
 
    /** 
    * To recieve network state changes 
    */ 
    public static void registerNetworkCheck() 
    { 
        IntentFilter i = new IntentFilter();
10
CodeRank
This code example shows how to use the following methods:isConnected
This code example shows how to use the following methods:isAvailable, isConnected
    public void onReceive(Context context, Intent intent) {
        if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
            final ConnectivityManager cm = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            final NetworkInfo ni = cm.getActiveNetworkInfo();
            final boolean scheduleSync = ni != null && ni.isAvailable() && ni.isConnected();
            SyncService.schedule(context, scheduleSync);
        } 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:isConnected
This code example shows how to use the following methods:isAvailable, isConnected
            } 
             
            public boolean isOnline() throws ConnectionException { 
            	    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            	    NetworkInfo ni = cm.getActiveNetworkInfo();
            	    if (ni!=null && ni.isAvailable() && ni.isConnected()) {
            	        return true; 
            	    } else { 
            	        return false;   
            	    }	 
            } 
         
         
         
 
 
	 
} 
8
CodeRank
This code example shows how to use the following methods:getType, isConnected
  protected boolean isConnected() { 
    NetworkInfo info = connectivityManager.getNetworkInfo(TYPE_MOBILE_MMS);
 
    Log.w("MmsService", "NetworkInfo: " + info);
 
    if ((info == null) || (info.getType() != TYPE_MOBILE_MMS) || !info.isConnected())
      return false; 
 
    return true; 
  } 
 
  protected abstract String getConnectivityAction();
 
  protected void issueConnectivityRequest() { 
    int status = connectivityManager.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, FEATURE_ENABLE_MMS);
 
    if (status == APN_ALREADY_ACTIVE) {
      issueConnectivityChange(); 
    } else if (connectivityListener == null) {
      IntentFilter filter  = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
7
CodeRank
This code example shows how to use the following methods:isConnected
    public static boolean isNetworkConnected(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        if (activeNetworkInfo != null) {
            return activeNetworkInfo.isConnected();
        } 
        return false; 
    } 
 
    /** 
     * Whether WiFi has an active, usable connection. 
     *  
     * @param context 
     * @return 
     */ 
    public static boolean isWifiConnected(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo wifiNetworkInfo = connectivityManager
10
CodeRank
This code example shows how to use the following methods:isAvailable, isConnected
 
        XmppService service = XmppService.getInstance();
        if (service != null) {
            NetworkInfo network = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
                // if no network, disconnect 
            if (network == null || !network.isAvailable()) {
                service.clearConnection();
            } else { 
                // connect if not already connected 
                if (network.isConnected() && !service.isConnected()) {
                    service.initConnection();
                } 
            } 
        } 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:isConnected, isConnectedOrConnecting
	public boolean isConnected() { 
		final NetworkInfo ni = connectivityManager.getActiveNetworkInfo();
		if (ni == null) {
			//sometime when wifi is connecting, ni is null so check wifi explicitly 
			final NetworkInfo wifiConnectivityInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
			if (wifiConnectivityInfo.isConnected() || wifiConnectivityInfo.isConnectedOrConnecting()) {
				return true; 
			} 
 
			return true; 
		} else { 
			final State state = ni.getState();
			if (state.equals(State.CONNECTED) || state.equals(State.CONNECTING)) {
				return true; 
			} 
 
			return false; 
		} 
	} 
 
8
CodeRank

Related NetworkInfo isConnected Questions & Answers:

isConnected Method Overview
Indicates whether network connectivity exists and it is possible to establish connections and pass data.
See Code Examples for other Android NetworkInfo Methods: