Example usage for android.net ConnectivityManager TYPE_MOBILE

List of usage examples for android.net ConnectivityManager TYPE_MOBILE

Introduction

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

Prototype

int TYPE_MOBILE

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

Click Source Link

Document

A Mobile data connection.

Usage

From source file:Main.java

/**
 * get mobile NetWork Type/*from   w  w w.j ava  2  s.  com*/
 * 
 * @param context
 * @return
 */
public static String getNetWorkType(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo workinfo = connectivityManager.getActiveNetworkInfo();
    if (workinfo != null) {
        if (workinfo.getType() == ConnectivityManager.TYPE_BLUETOOTH) {
            return "b";
        }
        if (workinfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            return "m";
        }
        if (workinfo.getType() == ConnectivityManager.TYPE_WIFI) {
            return "w";
        }
    }
    return null;
}

From source file:Main.java

public static String getNetworkState(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    String returnValue = "";
    if (null != activeNetwork) {
        if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
            returnValue = "wifi";
        else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE)
            returnValue = "mobile" + "_" + getNetworkType(context);
        else//  ww  w .jav  a2  s . c  om
            returnValue = "Unknown";
    } else
        returnValue = "Not connected";
    return returnValue;
}

From source file:Main.java

public static int getNetworkState(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    // Wifi//from  ww  w  . j  a v  a 2s  .c  om
    State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    if (state == State.CONNECTED || state == State.CONNECTING) {
        return NETWORN_WIFI;
    }

    // 3G
    state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
    if (state == State.CONNECTED || state == State.CONNECTING) {
        return NETWORN_MOBILE;
    }
    return NETWORN_NONE;
}

From source file:Main.java

/**
 * method to check if internet is connected or not
 *
 * @param mContext Context//from  www. ja v  a  2s .c  om
 * @return true if connected else false
 */
public static boolean isInternetAvailable(Context mContext) {

    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNetwork != null && wifiNetwork.isConnected()) {
        return true;
    }

    NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (mobileNetwork != null && mobileNetwork.isConnected()) {
        return true;
    }

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (activeNetwork != null && activeNetwork.isConnected()) {
        return true;
    }

    return false;
}

From source file:Main.java

public static int getNetworkState(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    // Wifi/*from   w w  w .j  a  v  a2s . c o  m*/
    NetworkInfo.State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING) {
        return NETWORN_WIFI;
    }

    // 3G
    state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
    if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING) {
        return NETWORN_MOBILE;
    }
    return NETWORN_NONE;
}

From source file:Main.java

public static int isNetworkAvailable(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (NetworkInfo anInfo : info) {
                if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
                    if (anInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                        return 1;
                    } else if (anInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                        String extraInfo = anInfo.getExtraInfo();
                        if ("cmwap".equalsIgnoreCase(extraInfo) || "cmwap:gsm".equalsIgnoreCase(extraInfo)) {
                            return 2;
                        }/*from   www .  j a  v  a 2  s  .c  o m*/
                        return 3;
                    }
                }
            }
        }
    }
    return 0;
}

From source file:Main.java

public static int isNetworkAvailable(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        return 0;
    } else {// w  ww . j av  a2 s . c  o  m
        NetworkInfo[] infos = connectivity.getAllNetworkInfo();
        if (infos != null) {
            for (NetworkInfo info : infos) {
                if (info.getState() == NetworkInfo.State.CONNECTED) {
                    if (info.getType() == ConnectivityManager.TYPE_WIFI) {
                        return 1;
                    } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
                        String extraInfo = info.getExtraInfo();
                        if ("cmwap".equalsIgnoreCase(extraInfo) || "cmwap:gsm".equalsIgnoreCase(extraInfo))
                            return 2;
                        return 3;
                    }
                }
            }
        }
    }
    return 0;
}

From source file:Main.java

static public boolean isMobile(NetworkInfo networkInfo) {
    return isNetworkType(networkInfo, ConnectivityManager.TYPE_MOBILE)
            || isNetworkType(networkInfo, CONNECTIVITY_TYPE_WIMAX);
}

From source file:Main.java

/**
 * checks if there is WI-FI or network connection available
 * @param currentActivity/* ww w .ja va  2s .  c om*/
 * @return
 */
public static boolean isInternetAvailable(Context currentActivity) {
    final ConnectivityManager conectivityManager = (ConnectivityManager) currentActivity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = conectivityManager.getActiveNetworkInfo();
    if (networkInfo != null) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            if (networkInfo.isConnected()) {
                return true;
            }
        } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            if (networkInfo.isConnected()) {
                return true;
            }
        }
    }

    return false;
}

From source file:Main.java

public static boolean checkNetworkAvailable(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        return false;
    } else {/*from w w w  .  j av a  2 s .c  om*/
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    NetworkInfo netWorkInfo = info[i];
                    if (netWorkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                        return true;
                    } else if (netWorkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                        return true;
                    }
                }
            }
        }
    }

    return false;

}