Example usage for android.telephony TelephonyManager NETWORK_TYPE_UNKNOWN

List of usage examples for android.telephony TelephonyManager NETWORK_TYPE_UNKNOWN

Introduction

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

Prototype

int NETWORK_TYPE_UNKNOWN

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

Click Source Link

Document

Network type is unknown

Usage

From source file:com.android.profilerapp.network.NetworkFragment.java

private Thread getStatisticThread() {
    return new Thread(new Runnable() {

        private Statistics statistics;
        private long[] myStartBytes;
        private long[] myBytes;

        private void initialize() {
            statistics = new Statistics();
            myStartBytes = getTrafficBytes(Integer.toString(myUid));
        }//from w w w . j  a v  a 2  s.  c o m

        @Override
        public void run() {
            initialize();
            while (!Thread.currentThread().isInterrupted()) {
                myBytes = getTrafficBytes(Integer.toString(myUid));
                statistics.sendBytesFromFile = myBytes[0] - myStartBytes[0];
                statistics.receiveBytesFromFile = myBytes[1] - myStartBytes[1];

                // Gets the bytes from API too, because API read is later than file read, API results may be a little larger.
                myBytes[0] = TrafficStats.getUidTxBytes(myUid) - myStartBytes[0];
                myBytes[1] = TrafficStats.getUidRxBytes(myUid) - myStartBytes[1];
                if (statistics.sendBytesFromFile > myBytes[0] || statistics.receiveBytesFromFile > myBytes[1]) {
                    Log.d(TAG, String.format(
                            "Bytes reported not in sync. TrafficStats: %1$d, %2$d, getTrafficBytes: %3$d, %4$d",
                            myBytes[0], myBytes[1], statistics.sendBytesFromFile,
                            statistics.receiveBytesFromFile));
                }

                NetworkInfo networkInfo = myConnectivityManager.getActiveNetworkInfo();
                statistics.networkName = networkInfo != null
                        && networkInfo.getSubtype() != TelephonyManager.NETWORK_TYPE_UNKNOWN
                                ? networkInfo.getSubtypeName()
                                : networkInfo.getTypeName();
                statistics.radioStatus = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
                        ? myConnectivityManager.isDefaultNetworkActive() ? "Radio high power"
                                : "Radio not high power"
                        : "Radio status unknown";
                statistics.openConnectionCount = getConnectionCount(Integer.toString(myUid));
                postStatistics(statistics);
                try {
                    Thread.currentThread().sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}

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

/** Called when the activity is first created. */
@Override//  w  w w .j  a va  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  . java 2s  . 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:com.wiyun.engine.network.Network.java

static int getNetworkType() {
    NetworkType type = NetworkType.NONE;

    if (isWifiConnected()) {
        type = NetworkType.WIFI;//w w  w. j  a va  2s  .  com
    } else {
        Context context = Director.getInstance().getContext();
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        if (tm == null)
            type = NetworkType.NONE;
        else {
            int t = tm.getNetworkType();
            if (t == TelephonyManager.NETWORK_TYPE_GPRS || t == TelephonyManager.NETWORK_TYPE_UNKNOWN)
                type = NetworkType.G2;
            else if (t == TelephonyManager.NETWORK_TYPE_EDGE)
                type = NetworkType.EDGE;
            else
                type = NetworkType.G3;
        }
    }

    return type.ordinal();
}

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   ww w  . j  a  va2  s  .c  o m
 * @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;

    }
}

From source file:at.alladin.rmbt.android.util.InformationCollector.java

public void reset() {

    testServerName = "";
    lastLocation = null;//  w  w w .  jav  a 2s. com

    lastNetworkType.set(TelephonyManager.NETWORK_TYPE_UNKNOWN);
    illegalNetworkTypeChangeDetcted.set(false);

    // create and load default properties
    fullInfo = new Properties();

    fullInfo.setProperty("UUID", "");

    fullInfo.setProperty("PLATTFORM", "");
    fullInfo.setProperty("OS_VERSION", "");
    fullInfo.setProperty("API_LEVEL", "");

    fullInfo.setProperty("DEVICE", "");
    fullInfo.setProperty("MODEL", "");
    fullInfo.setProperty("PRODUCT", "");

    fullInfo.setProperty("CLIENT_NAME", "");
    fullInfo.setProperty("CLIENT_SOFTWARE_VERSION", "");

    fullInfo.setProperty("NETWORK_TYPE", "");

    fullInfo.setProperty("TELEPHONY_PHONE_TYPE", "");
    fullInfo.setProperty("TELEPHONY_DATA_STATE", "");

    fullInfo.setProperty("TELEPHONY_NETWORK_COUNTRY", "");
    fullInfo.setProperty("TELEPHONY_NETWORK_OPERATOR", "");
    fullInfo.setProperty("TELEPHONY_NETWORK_OPERATOR_NAME", "");

    fullInfo.setProperty("TELEPHONY_NETWORK_SIM_COUNTRY", "");
    fullInfo.setProperty("TELEPHONY_NETWORK_SIM_OPERATOR", "");
    fullInfo.setProperty("TELEPHONY_NETWORK_SIM_OPERATOR_NAME", "");

    fullInfo.setProperty("TELEPHONY_NETWORK_IS_ROAMING", "");

    fullInfo.setProperty("WIFI_SSID", "");
    fullInfo.setProperty("WIFI_BSSID", "");
    fullInfo.setProperty("WIFI_NETWORK_ID", "");
    // fullInfo.setProperty("WIFI_LINKSPEED", "");
    // fullInfo.setProperty("WIFI_RSSI", "");
    fullInfo.setProperty("WIFI_SUPPLICANT_STATE", "");
    fullInfo.setProperty("WIFI_SUPPLICANT_STATE_DETAIL", "");

    /*
     * fullInfo.setProperty("GEO_TIME", ""); fullInfo.setProperty("GEO_LAT",
     * ""); fullInfo.setProperty("GEO_LONG","");
     * fullInfo.setProperty("GEO_ACCURACY", "");
     * fullInfo.setProperty("GEO_ALTITUDE", "");
     * fullInfo.setProperty("GEO_BEARING", "");
     * fullInfo.setProperty("GEO_SPEED", "");
     * fullInfo.setProperty("GEO_PROVIDER", "");
     */

    clearLists();
}

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  a v  a  2  s  .co  m
 * @return 0 for unknown, 2 for 2G and 3 for 3G.
 */
public static String getNetworkName(int networkType) {
    switch (networkType) {
    case TelephonyManager.NETWORK_TYPE_GPRS: // < 2g - tier 1 because data rate is <64 kbps
        return "GPRS";

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

    case TelephonyManager.NETWORK_TYPE_EVDO_0: //3g
        return "EVDO0";
    case TelephonyManager.NETWORK_TYPE_EVDO_A: //3g
        return "EVDOA";
    case TelephonyManager.NETWORK_TYPE_HSDPA: //3g
        return "HSDPA";
    case TelephonyManager.NETWORK_TYPE_HSPA: //3g
        return "HSPA";
    case TelephonyManager.NETWORK_TYPE_HSUPA: //3g
        return "HSUPA";
    case TelephonyManager.NETWORK_TYPE_UMTS: //3g
        return "UMTS";

    // 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 PhoneState.NETWORK_NEWTYPE_HSPAP: //3.5g HSPA+
        return "HSPA+";
    case PhoneState.NETWORK_NEWTYPE_EVDOB: //3.5g
        return "EVDOB";
    case PhoneState.NETWORK_NEWTYPE_EHRPD: //3.5g
        return "eHRPD";

    case PhoneState.NETWORK_NEWTYPE_LTE: // true 4g
        return "LTE";

    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
    default:
        return "Unknown";
    }
}

From source file:com.SecUpwN.AIMSICD.activities.MapViewer.java

/**
 * Loads Signal Strength Database details to plot on the map,
 * only entries which have a location (lon, lat) are used.
 *//*from  w w  w  . j a v a  2 s .c o m*/
private void loadEntries() {
    final int SIGNAL_SIZE_RATIO = 15;
    int signal;
    int color;
    mMap.clear();
    CircleOptions circleOptions;
    mDbHelper.open();
    Cursor c = mDbHelper.getCellData();
    if (c.moveToFirst()) {
        do {
            final int cellID = c.getInt(0);
            final int lac = c.getInt(1);
            final int net = c.getInt(2);
            final double dlat = Double.parseDouble(c.getString(3));
            final double dlng = Double.parseDouble(c.getString(4));
            if (dlat == 0.0 && dlng == 0.0) {
                continue;
            }
            signal = c.getInt(5);
            if (signal <= 0) {
                signal = 20;
            }

            if ((dlat != 0.0) || (dlng != 0.0)) {
                loc = new LatLng(dlat, dlng);
                switch (net) {
                case TelephonyManager.NETWORK_TYPE_UNKNOWN:
                    color = 0xF0F8FF;
                    break;
                case TelephonyManager.NETWORK_TYPE_GPRS:
                    color = 0xA9A9A9;
                    break;
                case TelephonyManager.NETWORK_TYPE_EDGE:
                    color = 0x87CEFA;
                    break;
                case TelephonyManager.NETWORK_TYPE_UMTS:
                    color = 0x7CFC00;
                    break;
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                    color = 0xFF6347;
                    break;
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                    color = 0xFF00FF;
                    break;
                case TelephonyManager.NETWORK_TYPE_HSPA:
                    color = 0x238E6B;
                    break;
                case TelephonyManager.NETWORK_TYPE_CDMA:
                    color = 0x8A2BE2;
                    break;
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                    color = 0xFF69B4;
                    break;
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                    color = 0xFFFF00;
                    break;
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                    color = 0x7CFC00;
                    break;
                default:
                    color = 0xF0F8FF;
                    break;
                }

                // Add Signal radius circle based on signal strength
                circleOptions = new CircleOptions().center(loc).radius(signal * SIGNAL_SIZE_RATIO)
                        .fillColor(color).strokeColor(color).visible(true);

                mMap.addCircle(circleOptions);

                // Add map marker for CellID
                Marker marker = mMap.addMarker(
                        new MarkerOptions().position(loc).draggable(false).title("CellID - " + cellID));
                mMarkerMap.put(marker, new MarkerData("" + cellID, "" + loc.latitude, "" + loc.longitude,
                        "" + lac, "", "", "", false));
            }

        } while (c.moveToNext());
    } else {
        Helpers.msgShort(this, "No tracked locations found to overlay on map.");
    }

    if (loc != null && (loc.latitude != 0.0 && loc.longitude != 0.0)) {
        CameraPosition POSITION = new CameraPosition.Builder().target(loc).zoom(16).build();
        mMap.animateCamera(CameraUpdateFactory.newCameraPosition(POSITION));
    } else {
        if (mBound) {
            // Try and find last known location and zoom there
            Location lastLoc = mAimsicdService.lastKnownLocation();
            if (lastLoc != null && lastLoc.hasAccuracy()) {
                loc = new LatLng(lastLoc.getLatitude(), lastLoc.getLongitude());
                CameraPosition POSITION = new CameraPosition.Builder().target(loc).zoom(16).build();

                mMap.animateCamera(CameraUpdateFactory.newCameraPosition(POSITION));
            } else {
                //Use Mcc to move camera to an approximate location near Countries Capital
                int mcc = mAimsicdService.mDevice.mCell.getMCC();
                double[] d = mDbHelper.getDefaultLocation(mcc);
                loc = new LatLng(d[0], d[1]);
                CameraPosition POSITION = new CameraPosition.Builder().target(loc).zoom(13).build();

                mMap.animateCamera(CameraUpdateFactory.newCameraPosition(POSITION));
            }
        }
    }

    loadOpenCellIDMarkers();
    c.close();
    mDbHelper.close();
}

From source file:at.alladin.rmbt.android.test.RMBTTask.java

public void runNDT() {
    final NDTRunner ndtRunner = new NDTRunner();
    ndtRunnerHolder.set(ndtRunner);/*from  w  ww .  j a va 2s  .co m*/

    Log.d(LOG_TAG, "ndt status RUNNING");

    final String ndtNetworkType;
    final int networkType = getNetworkType();
    switch (networkType) {
    case InformationCollector.NETWORK_WIFI:
        ndtNetworkType = NdtTests.NETWORK_WIFI;
        break;

    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        ndtNetworkType = NdtTests.NETWORK_UNKNOWN;
        break;

    default:
        ndtNetworkType = NdtTests.NETWORK_MOBILE;
        break;
    }

    ndtRunner.runNDT(ndtNetworkType, ndtRunner.new UiServices() {

        @Override
        public void sendResults() {
            client.getControlConnection().sendNDTResult(this, null);
        }

        public boolean wantToStop() {
            if (super.wantToStop())
                return true;

            if (cancelled.get()) {
                cancel();
                return true;
            }
            return false;
        }
    });
}

From source file:com.wbtech.common.CommonUtil.java

/**
 * ????/*w  w w  . j a  v a2s. c om*/
 * @param context
 * @return  WIFI MOBILE
 */
public static String getNetworkType(Context context) {
    //     ConnectivityManager connectionManager = (ConnectivityManager)
    //      context.getSystemService(Context.CONNECTIVITY_SERVICE);    
    //      NetworkInfo networkInfo = connectionManager.getActiveNetworkInfo();
    TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    int type = manager.getNetworkType();
    String typeString = "UNKOWN";
    if (type == TelephonyManager.NETWORK_TYPE_CDMA) {
        typeString = "CDMA";
    }
    if (type == TelephonyManager.NETWORK_TYPE_EDGE) {
        typeString = "EDGE";
    }
    if (type == TelephonyManager.NETWORK_TYPE_EVDO_0) {
        typeString = "EVDO_0";
    }
    if (type == TelephonyManager.NETWORK_TYPE_EVDO_A) {
        typeString = "EVDO_A";
    }
    if (type == TelephonyManager.NETWORK_TYPE_GPRS) {
        typeString = "GPRS";
    }
    if (type == TelephonyManager.NETWORK_TYPE_HSDPA) {
        typeString = "HSDPA";
    }
    if (type == TelephonyManager.NETWORK_TYPE_HSPA) {
        typeString = "HSPA";
    }
    if (type == TelephonyManager.NETWORK_TYPE_HSUPA) {
        typeString = "HSUPA";
    }
    if (type == TelephonyManager.NETWORK_TYPE_UMTS) {
        typeString = "UMTS";
    }
    if (type == TelephonyManager.NETWORK_TYPE_UNKNOWN) {
        typeString = "UNKOWN";
    }

    return typeString;
}