Example usage for android.net ConnectivityManager getAllNetworkInfo

List of usage examples for android.net ConnectivityManager getAllNetworkInfo

Introduction

In this page you can find the example usage for android.net ConnectivityManager getAllNetworkInfo.

Prototype

@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@NonNull
public NetworkInfo[] getAllNetworkInfo() 

Source Link

Document

Returns connection status information about all network types supported by the device.

Usage

From source file:it.sasabz.android.sasabus.classes.hafas.XMLAsyncRequest.java

/**
 * this method checks if a networkconnection is active or not
 * @return boolean if the network is reachable or not
 *///from  w  ww  .j  av  a2  s  .  co  m
private boolean haveNetworkConnection() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) (activity.getSystemService(Context.CONNECTIVITY_SERVICE));
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        //testing WIFI connection
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        //testing GPRS/EDGE/UMTS/HDSPA/HUSPA/LTE connection
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:it.sasabz.android.sasabus.InfoActivity.java

/**
* this method checks if a networkconnection is active or not
* @return boolean if the network is reachable or not
*///from  w  w w  . j  a va  2s.  c  o  m
private boolean haveNetworkConnection() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) (this.getSystemService(Context.CONNECTIVITY_SERVICE));
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        //testing WIFI connection
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        //testing GPRS/EDGE/UMTS/HDSPA/HUSPA/LTE connection
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:edu.missouri.bas.service.SensorService.java

public static boolean checkDataConnectivity() {
    ConnectivityManager connectivity = (ConnectivityManager) serviceContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }//  w w  w .ja v  a2 s .  c om
            }
        }
    }
    return false;
}

From source file:com.toppatch.mv.ui.activities.MainActivity.java

private boolean isConnectingToInternet() {
    ConnectivityManager connectivity = (ConnectivityManager) this
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null)
            for (int i = 0; i < info.length; i++)
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }//from w  w  w. j  av a2 s .  c om

    }
    return false;
}

From source file:jieehd.villain.updater.checkInBackground.java

public boolean haveNetworkConnection(Context mContext) {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;

    }//from w  w w  .  ja  v a  2  s . c  o  m
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:de.blinkt.openvpn.ActivityDashboard.java

public static boolean isInternetAvailable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm == null)
        return false;

    NetworkInfo[] info = cm.getAllNetworkInfo();
    if (info == null)
        return false;

    for (int i = 0; i < info.length; i++) {
        if (info[i].getState() == NetworkInfo.State.CONNECTED)
            return true;
    }//  w  ww. j a v  a 2  s.co  m

    return false;
}

From source file:app.uni.my.myapplication.HeaderActivity.java

public boolean isConnectingToInternet() {
    ConnectivityManager connectivity = (ConnectivityManager) getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null)
            for (int i = 0; i < info.length; i++)
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }//  w  w w  . j  ava2 s .  c  o m

    }
    return false;
}

From source file:com.honeycomb.cocos2dx.Soccer.java

public boolean isConnectingToInternet() {
    ConnectivityManager connectivity = (ConnectivityManager) this
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null)
            for (int i = 0; i < info.length; i++)
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }/*from   w  ww  . j  av  a2 s .c  o m*/

    }
    return false;
}

From source file:com.moodmap.SplashScreenActivity.java

public boolean networkStatus(Activity context) {
    boolean status = false;
    int i = 0;//from   w  w w. jav  a 2  s .  c  o m
    try {
        String service = Context.CONNECTIVITY_SERVICE;
        ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(service);
        connectivity.setNetworkPreference(1);

        NetworkInfo networkInfo[] = connectivity.getAllNetworkInfo();
        int cnt = networkInfo.length;

        for (i = 0; i < cnt; i++) {

            if (networkInfo[i].isConnected() == true) {
                status = true;
                Log.v("Network Provider", "" + networkInfo[i].getTypeName());
            }
        }
    } catch (Exception ee) {
        ee.printStackTrace();
    }
    Log.v("networkStatus", "##########" + status);
    return status;
}