Example usage for android.telephony TelephonyManager NETWORK_TYPE_EDGE

List of usage examples for android.telephony TelephonyManager NETWORK_TYPE_EDGE

Introduction

In this page you can find the example usage for android.telephony TelephonyManager NETWORK_TYPE_EDGE.

Prototype

int NETWORK_TYPE_EDGE

To view the source code for android.telephony TelephonyManager NETWORK_TYPE_EDGE.

Click Source Link

Document

Current network is EDGE

Usage

From source file:Main.java

/**
 * Whether is fast mobile network//www .jav a2s.c o m
 * 
 * @param context
 * @return
 */
private static boolean isFastMobileNetwork(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager == null) {
        return false;
    }

    switch (telephonyManager.getNetworkType()) {
    case TelephonyManager.NETWORK_TYPE_1xRTT:
        return false;
    case TelephonyManager.NETWORK_TYPE_CDMA:
        return false;
    case TelephonyManager.NETWORK_TYPE_EDGE:
        return false;
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
        return true;
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
        return true;
    case TelephonyManager.NETWORK_TYPE_GPRS:
        return false;
    case TelephonyManager.NETWORK_TYPE_HSDPA:
        return true;
    case TelephonyManager.NETWORK_TYPE_HSPA:
        return true;
    case TelephonyManager.NETWORK_TYPE_HSUPA:
        return true;
    case TelephonyManager.NETWORK_TYPE_UMTS:
        return true;
    case TelephonyManager.NETWORK_TYPE_EHRPD:
        return true;
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
        return true;
    case TelephonyManager.NETWORK_TYPE_HSPAP:
        return true;
    case TelephonyManager.NETWORK_TYPE_IDEN:
        return false;
    case TelephonyManager.NETWORK_TYPE_LTE:
        return true;
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        return false;
    default:
        return false;
    }
}

From source file:org.basdroid.common.NetworkUtils.java

/**
 * Check if the connection is fast//from   www  . j  av a2 s .c o m
 * @param type
 * @param subType
 * @return
 */
public static boolean isConnectionFast(int type, int subType) {
    if (type == ConnectivityManager.TYPE_WIFI) {
        return true;
    } else if (type == ConnectivityManager.TYPE_MOBILE) {
        switch (subType) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
            return false; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_CDMA:
            return false; // ~ 14-64 kbps
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return false; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
            return true; // ~ 400-1000 kbps
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
            return true; // ~ 600-1400 kbps
        case TelephonyManager.NETWORK_TYPE_GPRS:
            return false; // ~ 100 kbps
        case TelephonyManager.NETWORK_TYPE_HSDPA:
            return true; // ~ 2-14 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPA:
            return true; // ~ 700-1700 kbps
        case TelephonyManager.NETWORK_TYPE_HSUPA:
            return true; // ~ 1-23 Mbps
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return true; // ~ 400-7000 kbps
        /*
         * Above API level 7, make sure to set android:targetSdkVersion
         * to appropriate level to use these
         */
        case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11
            return true; // ~ 1-2 Mbps
        case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
            return true; // ~ 5 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
            return true; // ~ 10-20 Mbps
        case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
            return false; // ~25 kbps
        case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
            return true; // ~ 10+ Mbps
        // Unknown
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        default:
            return false;
        }
    } else {
        return false;
    }
}

From source file:com.commonsware.cwac.locpoll.demo.LocationReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    mContext = context;//  ww w .  ja va 2  s.  c  om

    File log = new File(Environment.getExternalStorageDirectory(), "LocationLog.txt");

    try {
        BufferedWriter out = new BufferedWriter(new FileWriter(log.getAbsolutePath(), log.exists()));

        out.write(new Date().toString());
        out.write(" : ");

        Bundle b = intent.getExtras();
        loc = (Location) b.get(LocationPoller.EXTRA_LOCATION);
        String msg;

        if (loc == null) {
            loc = (Location) b.get(LocationPoller.EXTRA_LASTKNOWN);

            if (loc == null) {
                msg = intent.getStringExtra(LocationPoller.EXTRA_ERROR);
            } else {
                msg = "TIMEOUT, lastKnown=" + loc.toString();
            }
        } else {
            msg = loc.toString();
            Log.d("Location Poller", msg);

            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

            if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSDPA)) {
                Log.d("Type", "3g");// for 3g HSDPA networktype will be return as
                // per testing(real) in device with 3g enable data
                // and speed will also matters to decide 3g network type
                type = 2;
            } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSPAP)) {
                Log.d("Type", "4g"); // /No specification for the 4g but from wiki
                // i found(HSPAP used in 4g)
                // http://goo.gl/bhtVT
                type = 3;
            } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_GPRS)) {
                Log.d("Type", "GPRS");
                type = 1;
            } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE)) {
                Log.d("Type", "EDGE 2g");
                type = 0;
            }

            /* Update the listener, and start it */
            MyListener = new MyPhoneStateListener();
            Tel = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
            Tel.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
        }

        if (msg == null) {
            msg = "Invalid broadcast received!";
        }

        out.write(msg);
        out.write("\n");
        out.close();
    } catch (IOException e) {
        Log.e(getClass().getName(), "Exception appending to log file", e);
    }
}

From source file:com.karpenstein.signalmon.SignalMonitorActivity.java

/** Called when the activity is first created. */
@Override/*from   w w  w . j a v a  2  s .co m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Get the UI
    textOut = (TextView) findViewById(R.id.textOut);

    // Get the telephony manager
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    // Create a new PhoneStateListener
    listener = new PhoneStateListener() {
        @Override
        public void onDataActivity(int direction) {
            String dirString = "N/A";
            switch (direction) {
            case TelephonyManager.DATA_ACTIVITY_NONE:
                dirString = "DATA_ACTIVITY_NONE";
                break;
            case TelephonyManager.DATA_ACTIVITY_IN:
                dirString = "DATA_ACTIVITY_IN";
                break;
            case TelephonyManager.DATA_ACTIVITY_OUT:
                dirString = "DATA_ACTIVITY_OUT";
                break;
            case TelephonyManager.DATA_ACTIVITY_INOUT:
                dirString = "DATA_ACTIVITY_INOUT";
                break;
            case TelephonyManager.DATA_ACTIVITY_DORMANT:
                dirString = "DATA_ACTIVITY_DORMANT";
                break;
            }
            textOut.append(dirString + "\n");
        }

        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            textOut.append(signalStrength.toString() + "\n");
        }

        @Override
        public void onDataConnectionStateChanged(int state, int networkType) {
            String stateString = "N/A";
            String netTypString = "N/A";
            switch (state) {
            case TelephonyManager.DATA_CONNECTED:
                stateString = "DATA_CONNECTED";
                break;
            case TelephonyManager.DATA_CONNECTING:
                stateString = "DATA_CONNECTING";
                break;
            case TelephonyManager.DATA_DISCONNECTED:
                stateString = "DATA_DISCONNECTED";
                break;
            case TelephonyManager.DATA_SUSPENDED:
                stateString = "DATA_SUSPENDED";
                break;
            }
            switch (networkType) {
            case TelephonyManager.NETWORK_TYPE_1xRTT:
                netTypString = "NETWORK_TYPE_1xRTT";
                break;
            case TelephonyManager.NETWORK_TYPE_CDMA:
                netTypString = "NETWORK_TYPE_CDMA";
                break;
            case TelephonyManager.NETWORK_TYPE_EDGE:
                netTypString = "NETWORK_TYPE_EDGE";
                break;
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
                netTypString = "NETWORK_TYPE_EVDO_0";
                break;
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
                netTypString = "NETWORK_TYPE_EVDO_A";
                break;
            case TelephonyManager.NETWORK_TYPE_GPRS:
                netTypString = "NETWORK_TYPE_GPRS";
                break;
            case TelephonyManager.NETWORK_TYPE_HSDPA:
                netTypString = "NETWORK_TYPE_HSDPA";
                break;
            case TelephonyManager.NETWORK_TYPE_HSPA:
                netTypString = "NETWORK_TYPE_HSPA";
                break;
            case TelephonyManager.NETWORK_TYPE_HSUPA:
                netTypString = "NETWORK_TYPE_HSUPA";
                break;
            case TelephonyManager.NETWORK_TYPE_IDEN:
                netTypString = "NETWORK_TYPE_IDE";
                break;
            case TelephonyManager.NETWORK_TYPE_UMTS:
                netTypString = "NETWORK_TYPE_UMTS";
                break;
            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
                netTypString = "NETWORK_TYPE_UNKNOWN";
                break;
            }
            textOut.append(String.format("onDataConnectionStateChanged: %s; %s\n", stateString, netTypString));
        }
    };

    // Register the listener with the telephony manager
    telephonyManager.listen(listener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
            | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_DATA_ACTIVITY);

    // start the NetServerService
    startService(new Intent(this, NetServerService.class));
}

From source file:org.basdroid.common.NetworkUtils.java

public static boolean isLTE(Context context) {
    NetworkInfo info = getNetworkInfo(context);
    if (info == null || !info.isConnected()) {
        return false;
    }/*from   w  w  w  .j a  va 2  s .c o  m*/

    int type = info.getType();
    int subType = info.getSubtype();

    if (type == ConnectivityManager.TYPE_WIFI) {
        return false;
    } else if (type == ConnectivityManager.TYPE_MOBILE) {
        switch (subType) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EDGE:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return false; // ~ 50-100 kbps
        /*
         * Above API level 7, make sure to set android:targetSdkVersion
         * to appropriate level to use these
         */
        case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11
        case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
        case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
        case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
            return false; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
            return true; // ~ 10+ Mbps
        // Unknown
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        default:
            return false;
        }
    } else {
        return false;
    }
}

From source file:hobby.wei.c.phone.Network.java

private static Type getType(NetworkInfo netInfo) {
    Type type;//from ww w  .  j a v  a 2  s .  com
    //?TYPE_WIFI?TYPE_MOBILE?TYPE_MOBILE_MMS
    if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) { //wifi?
        type = Type.WIFI;
    } else { //TYPE_WIFI
        switch (netInfo.getSubtype()) {
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            type = Type.NO_NET;
            break;
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_EDGE:
            type = Type.G2;
            break;
        case TelephonyManager.NETWORK_TYPE_UMTS:
        case TelephonyManager.NETWORK_TYPE_CDMA: //3G
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_1xRTT: //2.5GCDMA
        case TelephonyManager.NETWORK_TYPE_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_IDEN:
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
        case TelephonyManager.NETWORK_TYPE_EHRPD:
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            type = Type.G3;
            break;
        case TelephonyManager.NETWORK_TYPE_LTE:
            type = Type.G4;
            break;
        default:
            type = Type.G4;
            break;
        }
    }
    return type;
}

From source file:com.just.agentweb.AgentWebUtils.java

public static int checkNetworkType(Context context) {

    int netType = 0;
    //?/*from  w  w  w .j  a v  a 2  s .c o  m*/
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    //?NetworkInfo
    @SuppressLint("MissingPermission")
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    if (networkInfo == null) {
        return netType;
    }
    switch (networkInfo.getType()) {
    case ConnectivityManager.TYPE_WIFI:
    case ConnectivityManager.TYPE_WIMAX:
    case ConnectivityManager.TYPE_ETHERNET:
        return 1;

    case ConnectivityManager.TYPE_MOBILE:
        switch (networkInfo.getSubtype()) {
        case TelephonyManager.NETWORK_TYPE_LTE: // 4G
        case TelephonyManager.NETWORK_TYPE_HSPAP:
        case TelephonyManager.NETWORK_TYPE_EHRPD:
            return 2;
        case TelephonyManager.NETWORK_TYPE_UMTS: // 3G
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            return 3;

        case TelephonyManager.NETWORK_TYPE_GPRS: // 2G
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return 4;

        default:
            return netType;
        }

    default:

        return netType;
    }

}

From source file:de.stadtrallye.rallyesoft.services.UploadService.java

private void updateNetworkStatus() {
    NetworkInfo activeNetwork = connection.getActiveNetworkInfo();
    conn_available = activeNetwork.isConnected();

    switch (activeNetwork.getType()) {
    case (ConnectivityManager.TYPE_WIFI):
        conn_metered = false;//  www.jav  a2s. co m
        conn_slow = false;
        break;
    case (ConnectivityManager.TYPE_MOBILE): {
        conn_metered = true;
        switch (telephony.getNetworkType()) {
        case (TelephonyManager.NETWORK_TYPE_LTE | TelephonyManager.NETWORK_TYPE_HSPAP
                | TelephonyManager.NETWORK_TYPE_HSPA)://TODO more + check
            conn_slow = false;
            break;
        case (TelephonyManager.NETWORK_TYPE_EDGE | TelephonyManager.NETWORK_TYPE_GPRS):
            conn_slow = true;
            break;
        default:
            conn_slow = false;
            break;
        }
        break;
    }
    default:
        conn_metered = false;
        conn_slow = false;
        break;
    }
    Log.d(THIS,
            "Network: available: " + conn_available + ", metered: " + conn_metered + ", slow: " + conn_slow);
}

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

public static String getNetworkGeneration(int networkType) {
    switch (networkType) {
    case TelephonyManager.NETWORK_TYPE_1xRTT:
    case TelephonyManager.NETWORK_TYPE_CDMA:
    case TelephonyManager.NETWORK_TYPE_EDGE:
    case TelephonyManager.NETWORK_TYPE_GPRS:
    case TelephonyManager.NETWORK_TYPE_IDEN:
        return "2G";

    case TelephonyManager.NETWORK_TYPE_EHRPD:
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
    case TelephonyManager.NETWORK_TYPE_HSDPA:
    case TelephonyManager.NETWORK_TYPE_HSPA:
    case TelephonyManager.NETWORK_TYPE_HSPAP:
    case TelephonyManager.NETWORK_TYPE_HSUPA:
    case TelephonyManager.NETWORK_TYPE_UMTS:
    case NETWORK_TYPE_TD_SCDMA:
        return "3G";

    case TelephonyManager.NETWORK_TYPE_LTE:
    case NETWORK_TYPE_IWLAN:
        return "4G";

    default:/*from  w ww .  ja  v  a2  s  . co  m*/
        return "?G";
    }
}

From source file:org.restcomm.app.utillib.DataObjects.PhoneState.java

/**
 * Returns an integer to represent the generation of the network type.
 * Changed to a 5 tier designation where GPRS=tier1 and LTE=tier5
 * @param networkType/*from w  w w .  j  av  a  2s.c  om*/
 * @return 0 for unknown, 2 for 2G and 3 for 3G.
 */
public static int getNetworkGeneration(int networkType) {
    switch (networkType) {
    case TelephonyManager.NETWORK_TYPE_GPRS: // < 2g - tier 1 because data rate is <64 kbps
        return 1;

    case TelephonyManager.NETWORK_TYPE_1xRTT: //2g  (aka CDMA 2000)
    case TelephonyManager.NETWORK_TYPE_CDMA: //2g  (havent decided if plain cdma should be tier 1)
    case TelephonyManager.NETWORK_TYPE_EDGE: //2g
        return 2;

    case TelephonyManager.NETWORK_TYPE_EVDO_0: //3g
    case TelephonyManager.NETWORK_TYPE_EVDO_A: //3g
    case TelephonyManager.NETWORK_TYPE_UMTS: //3g
        return 3;

    // NEW NETWORK_TYPES - We need to rconsider these as 3G for now until we are sure of how to handle 4G 'outages'
    // because these technologies might only be active when transferring data and we don't want to treat as 4G outage when it reverts back to 3G
    case TelephonyManager.NETWORK_TYPE_HSDPA: //3.5g
    case TelephonyManager.NETWORK_TYPE_HSPA: //3.5g
    case TelephonyManager.NETWORK_TYPE_HSUPA: //3.5g

    case PhoneState.NETWORK_NEWTYPE_HSPAP: //3.5g HSPA+
    case PhoneState.NETWORK_NEWTYPE_EVDOB: //3.5g
    case PhoneState.NETWORK_NEWTYPE_EHRPD: //3.5g
        return 4;

    case PhoneState.NETWORK_NEWTYPE_LTE: // true 4g
        return 5;

    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        return 0;
    default:
        return 1;

    }
}