Android NetworkInfo - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:isConnectedOrConnecting
public class NetworkUtils { 
	 
	public static boolean isOnline(Context context) {
		ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo netInfo = cm.getActiveNetworkInfo();
		if (netInfo != null && netInfo.isConnectedOrConnecting()) {
			return true; 
		} 
		return false; 
	} 
 
} 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isAvailable
  } 
 
  protected boolean isConnectivityPossible() { 
    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(TYPE_MOBILE_MMS);
    Log.w("MmsService", "Got network info: " + networkInfo);
    return networkInfo != null  && networkInfo.isAvailable();
  } 
 
  protected void finishConnectivity() { 
    Log.w("MmsService", "Calling stop using network feature!");
    connectivityManager.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, FEATURE_ENABLE_MMS);
 
    if (connectivityListener != null) {
      context.unregisterReceiver(connectivityListener);
      connectivityListener = null;
    } 
 
    if (this.wakeLock.isHeld())
      this.wakeLock.release();
  } 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getType
		return networkInfo != null && networkInfo.isConnected();
	} 
 
	public boolean onWiFi() { 
		NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
		return connected() && networkInfo.getType() == TYPE_WIFI;
	} 
 
} 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isConnectedOrConnecting
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
 
        // Check if we are connected to an active data network. 
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        boolean isConnected = (activeNetwork != null) && activeNetwork.isConnectedOrConnecting();
 
        if (isConnected) {
            PackageManager pm = context.getPackageManager();
 
            ComponentName connectivityReceiver = new ComponentName(context,
                    IgnitedConnectivityChangedReceiver.class); 
            ComponentName locationReceiver = new ComponentName(context,
                    IgnitedLocationChangedReceiver.class); 
            ComponentName passiveLocationReceiver = new ComponentName(context,
                    IgnitedPassiveLocationChangedReceiver.class); 
 
            // The default state for this Receiver is disabled. it is only 
            // enabled when a Service disables updates pending connectivity. 
            pm.setComponentEnabledSetting(connectivityReceiver,
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isAvailable, isConnected
 
        if (PackageManager.PERMISSION_GRANTED == context.checkCallingOrSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE)) {
            ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
             
            object.put("available", wifi.isAvailable());
            object.put("connected", wifi.isConnected());
        } 
		 
		return object;
	} 
 
} 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getType
 
	@Override 
	public boolean isWifiConnected() { 
		ConnectivityManager mgr =  (ConnectivityManager) app.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo ni = mgr.getActiveNetworkInfo();
		return ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI;
	} 
 
	@Override 
	public boolean isInternetConnected() { 
		ConnectivityManager mgr = (ConnectivityManager) app.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo active = mgr.getActiveNetworkInfo();
		if(active == null){
			return false; 
		} else { 
			NetworkInfo.State state = active.getState();
			return state != NetworkInfo.State.DISCONNECTED && state != NetworkInfo.State.DISCONNECTING;
		} 
	} 
 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isConnected
	 * @return 
	 */ 
	public static boolean isNetworkAvailable(Context context) {
		ConnectivityManager connMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = connMgr.getActiveNetworkInfo();
		return info != null && info.isConnected();
	} 
} 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isAvailable, isConnected
	private static boolean isNotConnectedToNetwork(final ConnectivityManager cnnxManager) {
		if (isNull(cnnxManager)) {
			return false; 
		} 
		final NetworkInfo ni = cnnxManager.getActiveNetworkInfo();
		return ni == null || !ni.isAvailable() || !ni.isConnected();
	} 
 
	private static String temp(Temperature temperature) {
		return null != temperature ? temperature.abrev() : "N/A";
	} 
 
	private static String woeid(Woeid woeid) {
		return null != woeid ? woeid.getWoeid() : "N/A";
	} 
} 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android NetworkInfo Questions & Answers:

Other Android NetworkInfo Examples

16:			  if (connectivity != null) 
17:			  {
18:				  NetworkInfo[] info = connectivity.getAllNetworkInfo();
19:				  if (info != null) 
20:					  for (int i = 0; i < info.length; i++)

Read More

19:	          if (connectivity != null)
20:	          {
21:	              NetworkInfo[] info = connectivity.getAllNetworkInfo();
22:	              if (info != null)
23:	                  for (int i = 0; i < info.length; i++)

Read More

19:	          if (connectivity != null)
20:	          {
21:	              NetworkInfo[] info = connectivity.getAllNetworkInfo();
22:	              if (info != null)
23:	                  for (int i = 0; i < info.length; i++)

Read More

See Code Examples for Android NetworkInfo Methods: