Example usage for android.net ConnectivityManager TYPE_ETHERNET

List of usage examples for android.net ConnectivityManager TYPE_ETHERNET

Introduction

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

Prototype

int TYPE_ETHERNET

To view the source code for android.net ConnectivityManager TYPE_ETHERNET.

Click Source Link

Document

An Ethernet data connection.

Usage

From source file:Main.java

public static boolean checkEthernet(Context context) {
    ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = conn.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
    return networkInfo.isConnected();
}

From source file:Main.java

public static NetworkInfo getLanNetworkIfPossible(ConnectivityManager connMgr) {
    NetworkInfo result = null;/*from ww w .  j av a 2  s.  c o  m*/

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        result = connMgr.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
    }

    return result;
}

From source file:Main.java

public static boolean isEthernetDataEnable(Context context) throws Exception {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean isEthernetDataEnable = false;

    isEthernetDataEnable = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET)
            .isConnectedOrConnecting();//  ww  w . j av a 2 s .c o  m

    return isEthernetDataEnable;
}

From source file:Main.java

public static boolean isWifi(Context context) {
    NetworkInfo networkInfo = ((ConnectivityManager) (context.getSystemService(Context.CONNECTIVITY_SERVICE)))
            .getActiveNetworkInfo();/*from  w w  w  .ja  v  a2s.  c o  m*/
    return networkInfo != null && networkInfo.isConnected()
            && (networkInfo.getType() == ConnectivityManager.TYPE_WIFI
                    || networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET || networkInfo.getType() == 17
                    || networkInfo.getType() == -1 || networkInfo.getType() == 13
                    || networkInfo.getType() == 16);
}

From source file:Main.java

public static boolean CheckNetworkConnect(Context context) {
    boolean result = false;
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mobileInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    NetworkInfo wifiInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    NetworkInfo ethInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
    NetworkInfo activeInfo = manager.getActiveNetworkInfo();
    Log.v("networkInfo", "mobile:" + mobileInfo.isConnected() + "\n" + "wifi:" + wifiInfo.isConnected() + "\n"
            + "eth:" + ethInfo.isConnected() + "\n" + "active:" + activeInfo.getTypeName());
    if (wifiInfo.isConnected() || ethInfo.isConnected()) {
        result = true;/*  ww w  .  j  a  va 2 s  . co m*/
    }
    return result;
}

From source file:Main.java

public static boolean isChargeFreeNetworkAvailable(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = manager.getActiveNetworkInfo();
    return (activeNetworkInfo != null && activeNetworkInfo.isConnected()
            && (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI
                    || activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIMAX
                    || activeNetworkInfo.getType() == ConnectivityManager.TYPE_ETHERNET));
}

From source file:Main.java

static public String getMacAddress(Context context, ConnectivityManager connMananger) {
    Log.d(TAG, "getMacAddress");

    String macAddress = "";

    NetworkInfo info = connMananger.getActiveNetworkInfo();
    if (info != null && info.isConnected()) {
        int type = info.getType();

        Log.d(TAG, "connected type = " + type + " name " + info.getTypeName());

        if (type == ConnectivityManager.TYPE_WIFI) {
            WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            macAddress = wifiInfo.getMacAddress();
        } else if (type == ConnectivityManager.TYPE_ETHERNET || type == ConnectivityManager.TYPE_MOBILE) {
            String addressFileName = "/sys/class/net/eth0/address";
            File addressFile = new File(addressFileName);
            Log.d(TAG, "1");

            if (addressFile.exists()) {
                Log.d(TAG, "2");
                macAddress = readString(addressFile);
                Log.d(TAG, macAddress);//w  w w  .j  av a 2 s. c o m
            } else {
                addressFileName = "/sys/class/net/eth1/address";
                addressFile = new File(addressFileName);
                if (addressFile.exists()) {
                    macAddress = readString(addressFile);
                    Log.d(TAG, macAddress);
                }
            }
        } else {
            //other type;
        }
    }
    return macAddress;
}

From source file:Main.java

public static boolean isWifiAvailable(final Context context) {

    if (context != null) {
        final ConnectivityManager connManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo[] connections = connManager.getAllNetworkInfo();
        for (NetworkInfo netInfo : connections) {
            if (netInfo != null) {
                boolean connected = netInfo.isConnected();
                int connectType = netInfo.getType();

                if (connected)
                    if (connectType == ConnectivityManager.TYPE_WIFI
                            || connectType == ConnectivityManager.TYPE_ETHERNET)
                        return true;
            }//from  w  w w  . j  a  v a 2 s  .co m
        }
    }
    return false;
}

From source file:com.air.mobilebrowser.NetworkUtil.java

/**
 * Check the current status of internet connectivity.
 * This method iterates over the available network interfaces and
 * checks for an active connection.// w  w w  . ja  v  a2 s  .c o  m
 * @return true if a connection was detected, false otherwise.
 */
public static boolean haveInternetConnection(Context context) {
    if (context != null) {
        ConnectivityManager connectivityMgr = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo wifiInfo = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        NetworkInfo mobile = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        NetworkInfo wimax = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_WIMAX);
        NetworkInfo blue = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_BLUETOOTH);
        NetworkInfo ether = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);

        boolean hasInternet = false;

        if (wifiInfo != null && wifiInfo.getState() == NetworkInfo.State.CONNECTED) {
            hasInternet = true;
        } else if (mobile != null && mobile.getState() == NetworkInfo.State.CONNECTED) {
            hasInternet = true;
        } else if (wimax != null && wimax.getState() == NetworkInfo.State.CONNECTED) {
            hasInternet = true;
        } else if (blue != null && blue.getState() == NetworkInfo.State.CONNECTED) {
            hasInternet = true;
        } else if (ether != null && ether.getState() == NetworkInfo.State.CONNECTED) {
            hasInternet = true;
        }

        return hasInternet;
    }

    return false;
}

From source file:com.seadee.degree.service.NetworkStateReceiver.java

public static boolean isEthernetConnected() {
    if (connectmanager == null)
        connectmanager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return connectmanager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET).isConnected();
}