Example usage for android.net NetworkInfo isRoaming

List of usage examples for android.net NetworkInfo isRoaming

Introduction

In this page you can find the example usage for android.net NetworkInfo isRoaming.

Prototype

@Deprecated
public boolean isRoaming() 

Source Link

Document

Indicates whether the device is currently roaming on this network.

Usage

From source file:Main.java

/**
 * Check if roaming connection active.//from  w w  w.  j  a  v  a2  s  . c  o m
 *
 * @return
 */
private static boolean isConnectionRoaming(Context ctx) {
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();

    return ni != null && ni.isRoaming();

}

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 {// w  ww . j av  a2  s  .  co  m
        return false;
    }
}

From source file:Main.java

public static boolean hasInternet(Activity activity) {

    ConnectivityManager manager = (ConnectivityManager) activity

            .getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo info = manager.getActiveNetworkInfo();

    if (info == null || !info.isConnected()) {

        return false;
    }//from  w w  w  .  ja v  a 2 s.co  m
    if (info.isRoaming()) {
        // here is the roaming option you can change it if you want to

        // disable internet while roaming, just return false

        return true;
    }
    return true;
}

From source file:Main.java

public static String getNetworkConnType(Context context) {
    ConnectivityManager connectMgr = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (null == connectMgr) {
        return null;
    }//from   w  w  w.j  a  v  a2  s  .c o  m

    NetworkInfo info = connectMgr.getActiveNetworkInfo();
    if (info == null || !info.isConnected()) {
        return null;
    }
    if (info.isRoaming()) {
        // here is the roaming option you can change it if you want to
        // disable internet while roaming, just return false
        return null;
    }

    NetworkInfo mobileNetworkInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (null == mobileNetworkInfo) {
        return null;
    }
    NetworkInfo.State mobile = mobileNetworkInfo.getState();
    if (mobile == NetworkInfo.State.CONNECTED || mobile == NetworkInfo.State.CONNECTING) {
        return NETWORK_CONN_MOBILE;
    }

    NetworkInfo wifiNetworkInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (null == wifiNetworkInfo) {
        return null;
    }
    NetworkInfo.State wifi = wifiNetworkInfo.getState();
    if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) {
        return NETWORK_CONN_WIFI;
    }
    return null;
}

From source file:Main.java

public static int getNetState() {
    if (cm == null)
        return STATE_UNKNOWN;

    try {//  w  w w .  ja va  2 s. c o  m
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        if (activeNetwork == null || !activeNetwork.isConnected())
            return STATE_DISCONNECTED;

        if (activeNetwork.isRoaming())
            return STATE_ROAMING;

        return STATE_CONNECTED;
    } catch (Exception e) {
        /* java.lang.SecurityException can occur if
           android.permission.ACCESS_NETWORK_STATE is not given */
        Log.d(TAG, "ConnectivityManager failed", e);
        return STATE_UNKNOWN;
    }
}

From source file:com.marinamalynkina.android.nearbyplaces.PermissionUtils.java

public static boolean haveInternet(Context ctx) {

    NetworkInfo info = (NetworkInfo) ((ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();//ww w.jav  a  2  s. c o  m

    if (info == null || !info.isConnected()) {
        return false;
    }
    if (info.isRoaming()) {
        // here is the roaming option you can change it if you want to
        // disable internet while roaming, just return false
        return true;
    }
    return true;
}

From source file:edu.mit.mobile.android.locast.data.CastMedia.java

/**
 * Attempts to guess if the video player should show a high quality version of the video or a
 * lower bitrate version./*  ww w .j a v  a 2 s .c o m*/
 *
 * @return true if it seems as though playing high-quality would be expensive or wouldn't work
 */
public static boolean shouldShowLowQuality(Context context) {
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final boolean metered = ConnectivityManagerCompat.isActiveNetworkMetered(cm);
    final NetworkInfo net = cm.getActiveNetworkInfo();

    if (metered || net == null || net.isRoaming()) {
        return true;
    }

    // this is because these devices tend to not be able to be powerful enough to show the full
    // res video
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        return true;
    }

    final int type = net.getType();

    switch (type) {
    // generally these are fast and cheap/free
    case ConnectivityManager.TYPE_WIFI:
    case ConnectivityManager.TYPE_ETHERNET:
    case ConnectivityManager.TYPE_WIMAX:
        return false;

    default:
        return true;
    }
}

From source file:dev.ukanth.ufirewall.InterfaceTracker.java

private static InterfaceDetails getInterfaceDetails(Context context) {
    InterfaceDetails ret = new InterfaceDetails();

    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();

    if (info == null || info.isConnected() == false) {
        return ret;
    }/*from  w w  w  . jav a  2  s.c om*/

    switch (info.getType()) {
    case ConnectivityManager.TYPE_MOBILE:
    case ConnectivityManager.TYPE_MOBILE_DUN:
    case ConnectivityManager.TYPE_MOBILE_HIPRI:
    case ConnectivityManager.TYPE_MOBILE_MMS:
    case ConnectivityManager.TYPE_MOBILE_SUPL:
    case ConnectivityManager.TYPE_WIMAX:
        ret.isRoaming = info.isRoaming();
        ret.netType = ConnectivityManager.TYPE_MOBILE;
        ret.netEnabled = true;
        break;
    case ConnectivityManager.TYPE_WIFI:
    case ConnectivityManager.TYPE_BLUETOOTH:
    case ConnectivityManager.TYPE_ETHERNET:
        ret.netType = ConnectivityManager.TYPE_WIFI;
        ret.netEnabled = true;
        break;
    }
    getTetherStatus(context, ret);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
        OldInterfaceScanner.populateLanMasks(context, ITFS_WIFI, ret);
    } else {
        NewInterfaceScanner.populateLanMasks(context, ITFS_WIFI, ret);
    }

    return ret;
}

From source file:com.adam.aslfms.util.Util.java

public static NetworkStatus checkForOkNetwork(Context ctx) {

    AppSettings settings = new AppSettings(ctx);
    PowerOptions powerOptions = checkPower(ctx);

    NetworkOptions networkOptions = settings.getNetworkOptions(powerOptions);
    boolean roaming = settings.getSubmitOnRoaming(powerOptions);

    ConnectivityManager connectivityManager = (ConnectivityManager) ctx
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo();
    if (netInfo == null) {
        Log.d(TAG, "netInfo == null");
    }/*from w  ww  .  ja va 2 s .co m*/
    if (netInfo != null) {
        Log.d(TAG, "conn: " + netInfo.isConnected() + " : " + netInfo.toString());
    }

    if (netInfo == null || !netInfo.isConnected()) {
        return NetworkStatus.DISCONNECTED;
    }

    if (netInfo.isRoaming() && !roaming) {
        return NetworkStatus.UNFIT;
    }

    int netType = netInfo.getType();
    int netSubType = netInfo.getSubtype();

    Log.d(TAG, "netType: " + netType);
    Log.d(TAG, "netSubType: " + netSubType);

    if (networkOptions.isNetworkTypeForbidden(netType)) {
        Log.d(TAG, "Network type forbidden");
        return NetworkStatus.UNFIT;
    }
    if (networkOptions.isNetworkSubTypeForbidden(netType, netSubType)) {
        Log.d(TAG, "Network sub type forbidden");
        return NetworkStatus.UNFIT;
    }

    return NetworkStatus.OK;
}

From source file:android_network.hetnet.vpn_service.Util.java

public static boolean isRoaming(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo());
    return (ni != null && ni.isRoaming());
}