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

public static boolean hasConnected(Context context) {
    ConnectivityManager connectMgr = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mobNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    NetworkInfo wifiNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if ((mobNetInfo == null || !mobNetInfo.isConnected())
            && (wifiNetInfo == null || !wifiNetInfo.isConnected())) {
        return false;
    }/*from w  ww . ja v a 2 s.  co  m*/

    return true;
}

From source file:Main.java

public static boolean isMobileOnline(Context context) {
    ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    State mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();

    return mobile == State.CONNECTED;
}

From source file:Main.java

public static boolean isMobileNetwork(Context context) {
    NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();/*from w ww .  ja  va2 s  .c o m*/
    return (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE);
}

From source file:Main.java

private static boolean checkNetWork_b(Context context) {
    ConnectivityManager connectMgr = (ConnectivityManager) context
            .getSystemService(context.CONNECTIVITY_SERVICE);
    NetworkInfo mobNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    NetworkInfo wifiNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    NetworkInfo mNetworkInfo = connectMgr.getActiveNetworkInfo();
    boolean bmob = mobNetInfo.isConnected();
    boolean bwifi = wifiNetInfo.isConnected();
    if (!bmob && !bwifi) {
        // Log.i(TAG, "unconnect");
        // unconnect network
        return false;
    } else {//  w w  w .  j a  v  a 2  s  . c o  m
        // connect network
        return true;
    }

}

From source file:Main.java

public static boolean isMobileConnected(Context context) {
    ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (mgr == null)
        return false;
    NetworkInfo info = mgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (info == null)
        return false;
    NetworkInfo.State state = info.getState();
    return state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING;
}

From source file:Main.java

public static boolean isMOBILEConnected(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (networkInfo != null && networkInfo.isConnected()) {
        return true;
    }//  w w  w .ja  va 2 s  .c  o m
    return false;
}

From source file:Main.java

public static boolean isConnectedRoaming(Context context) {
    ConnectivityManager connec = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mobile = connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

    if (mobile != null && mobile.isConnected() && mobile.isRoaming()) {
        return true;
    } else {/*from   w w  w .  j a  v a  2s .c  o m*/
        return false;
    }
}

From source file:Main.java

public static boolean isMobileDataEnable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (networkInfo == null)
        return false;

    return networkInfo.isConnectedOrConnecting();
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager conMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    boolean availability = false;
    try {/* w  ww.  j a  v  a 2  s . co  m*/
        if (conMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED
                || conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
                        .getState() == NetworkInfo.State.CONNECTED) {
            availability = true;
        }
    } catch (Exception e) {
        return true;
    }
    return availability;
}

From source file:Main.java

public static boolean isMobileDataEnable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean isMobileDataEnable = false;
    isMobileDataEnable = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
            .isConnectedOrConnecting();//from  w w w. j  a va  2 s .  com

    return isMobileDataEnable;
}