Example usage for android.telephony TelephonyManager getNetworkType

List of usage examples for android.telephony TelephonyManager getNetworkType

Introduction

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

Prototype

@Deprecated
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public @NetworkType int getNetworkType() 

Source Link

Document

Return the current data network type.

Usage

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

/**
 * ????/*from ww  w.  j  a v a2  s . co m*/
 * @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;
}

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

public static int getNetworkType(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
    return tm.getNetworkType();
}

From source file:org.sipdroid.sipua.ui.Receiver.java

static boolean isFastGSM(int i) {
    TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);

    if (Sipdroid.market)
        return false;
    if (on_vpn() && (tm.getNetworkType() >= TelephonyManager.NETWORK_TYPE_EDGE))
        return PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                org.sipdroid.sipua.ui.Settings.PREF_VPN + (i != 0 ? i : ""),
                org.sipdroid.sipua.ui.Settings.DEFAULT_VPN);
    if (tm.getNetworkType() >= TelephonyManager.NETWORK_TYPE_UMTS)
        return PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                org.sipdroid.sipua.ui.Settings.PREF_3G + (i != 0 ? i : ""),
                org.sipdroid.sipua.ui.Settings.DEFAULT_3G);
    if (tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE)
        return PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                org.sipdroid.sipua.ui.Settings.PREF_EDGE + (i != 0 ? i : ""),
                org.sipdroid.sipua.ui.Settings.DEFAULT_EDGE);
    return false;
}

From source file:com.fallahpoor.infocenter.fragments.SimFragment.java

private String getNetworkType(TelephonyManager telephonyManager) {

    int intNetType = telephonyManager.getNetworkType();
    String netType;/*from   www  . j  a  va2s .co m*/

    switch (intNetType) {
    case TelephonyManager.NETWORK_TYPE_1xRTT:
        netType = getString(R.string.sim_sub_item_1xrtt);
        break;
    case TelephonyManager.NETWORK_TYPE_CDMA:
        netType = getString(R.string.sim_sub_item_cdma);
        break;
    case TelephonyManager.NETWORK_TYPE_EDGE:
        netType = getString(R.string.sim_sub_item_edge);
        break;
    case TelephonyManager.NETWORK_TYPE_EHRPD:
        netType = getString(R.string.sim_sub_item_ehrdp);
        break;
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
        netType = getString(R.string.sim_sub_item_evdo);
        break;
    case TelephonyManager.NETWORK_TYPE_GPRS:
        netType = getString(R.string.sim_sub_item_gprs);
        break;
    case TelephonyManager.NETWORK_TYPE_HSDPA:
        netType = getString(R.string.sim_sub_item_hsdpa);
        break;
    case TelephonyManager.NETWORK_TYPE_HSPA:
        netType = getString(R.string.sim_sub_item_hspa);
        break;
    case TelephonyManager.NETWORK_TYPE_HSPAP:
        netType = getString(R.string.sim_sub_item_hspap);
        break;
    case TelephonyManager.NETWORK_TYPE_HSUPA:
        netType = getString(R.string.sim_sub_item_hsupa);
        break;
    case TelephonyManager.NETWORK_TYPE_IDEN:
        netType = getString(R.string.sim_sub_item_iden);
        break;
    case TelephonyManager.NETWORK_TYPE_LTE:
        netType = getString(R.string.sim_sub_item_lte);
        break;
    case TelephonyManager.NETWORK_TYPE_UMTS:
        netType = getString(R.string.sim_sub_item_umts);
        break;
    default:
        netType = getString(R.string.unknown);
    }

    return netType;

}

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

@Override
public void onReceive(Context context, Intent intent) {
    mContext = context;// w ww  . j  a  v a  2 s.c  o  m

    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.example.testapplication.DialogLocation.java

@SuppressLint("InlinedApi")
@Override/*from ww w . j  a  v a2  s  .co m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mProgressBar = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge);
    mProgressBarInv = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge);
    mProgressBarInv.setVisibility(ProgressBar.GONE);

    mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

    mCriteria = new Criteria();
    int criteria = (mGpsPref) ? Criteria.POWER_HIGH : Criteria.POWER_MEDIUM;
    mCriteria.setPowerRequirement(criteria);

    mProvider = mLocationManager.getBestProvider(mCriteria, true);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    int telephonyInfo = tm.getNetworkType();

    boolean networkAvailable = true;

    if ((telephonyInfo == TelephonyManager.NETWORK_TYPE_UNKNOWN && !networkInfo.isConnected())
            || !mLocationManager.isProviderEnabled("network")) {
        networkAvailable = false;
    }

    int locationMode = -1;
    int locationType = -1;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        try {
            locationMode = Settings.Secure.getInt(getActivity().getContentResolver(),
                    Settings.Secure.LOCATION_MODE);
        } catch (SettingNotFoundException e) {
            e.printStackTrace();
        }

        if (locationMode == Settings.Secure.LOCATION_MODE_OFF
                || (!networkAvailable && (mProvider.matches("network"))))
            locationType = NO_LOCATION_SERVICES;
        else if (mGpsPref && (locationMode == Settings.Secure.LOCATION_MODE_SENSORS_ONLY
                || locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY))
            locationType = (locationMode == Settings.Secure.LOCATION_MODE_SENSORS_ONLY || !networkAvailable)
                    ? USING_ONLY_GPS_LOCATION
                    : USING_GPS_LOCATION_NETWORK_AVAILABLE;
        else if (mProvider.matches("network") && (locationMode == Settings.Secure.LOCATION_MODE_BATTERY_SAVING
                || locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY))
            locationType = USING_NETWORK_LOCATION;

    } else {
        if (mProvider.matches("passive") || !networkAvailable
                && (mProvider.matches("network") || (!mGpsPref && mProvider.matches("gps"))))
            locationType = NO_LOCATION_SERVICES;
        else if (mProvider.matches("gps") && mGpsPref)
            locationType = ((mProvider.matches("gps")) || !networkAvailable) ? USING_ONLY_GPS_LOCATION
                    : USING_GPS_LOCATION_NETWORK_AVAILABLE;
        else if (mProvider.matches("network"))
            locationType = USING_NETWORK_LOCATION;
    }

    switch (locationType) {
    case NO_LOCATION_SERVICES:
        builder.setTitle(DIALOG_LOCATION_NO_LOCATION_SERVICES_TITLE);
        builder.setMessage(DIALOG_LOCATION_NO_LOCATION_SERVICES_MESSAGE);
        builder.setNeutralButton(DIALOG_LOCATION_BUTTON_SETTINGS, noNetworkButton);
        mAbortRequest = true;
        break;
    case USING_ONLY_GPS_LOCATION:
        builder.setTitle(DIALOG_LOCATION_UPDATING_GPS_TITLE);
        builder.setMessage(DIALOG_LOCATION_ONLY_GPS_MESSAGE);
        builder.setNeutralButton(DIALOG_LOCATION_BUTTON_SETTINGS, noNetworkButton);
        builder.setView(mProgressBar);
        break;
    case USING_GPS_LOCATION_NETWORK_AVAILABLE:
        builder.setTitle(DIALOG_LOCATION_UPDATING_GPS_TITLE);
        builder.setPositiveButton(DIALOG_LOCATION_USE_NETWORK, null);
        builder.setView(mProgressBar);
        break;
    case USING_NETWORK_LOCATION:
        builder.setView(mProgressBar);
        builder.setTitle(DIALOG_LOCATION_UPDATING_NETWORK_TITLE);
        break;
    }

    builder.setNegativeButton(DIALOG_LOCATION_CANCEL, cancelListener);
    builder.setOnKeyListener(new DialogInterface.OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                mCallback.onLocationFound(null, mFragmentId);
                mLocationManager.removeUpdates(DialogLocation.this);
                Toast.makeText(getActivity(), "Location request cancelled", Toast.LENGTH_SHORT).show();
                dialog.cancel();
                return true;
            }
            return false;
        }
    });

    mRealDialog = builder.create();
    mRealDialog.setOnShowListener(usingNetwork);
    mRealDialog.setCanceledOnTouchOutside(false);
    return mRealDialog;
}

From source file:com.nearnotes.NoteLocation.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the Builder class for convenient dialog construction
    Bundle extras = getArguments();/*from ww  w.jav a2  s  .co m*/
    mTypeFrag = extras.getInt("TypeFrag");

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
    Boolean gpsPref = sharedPref.getBoolean("pref_key_ignore_gps", false);
    mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    mCriteria = new Criteria();
    if (gpsPref) {
        mCriteria.setPowerRequirement(Criteria.POWER_HIGH);
    } else
        mCriteria.setPowerRequirement(Criteria.POWER_MEDIUM);
    mProvider = mLocationManager.getBestProvider(mCriteria, true);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    boolean oldApi = false;
    int locationMode = 4;
    Log.e("mProvider", mProvider);

    ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    boolean networkAvailable = true;

    TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    boolean networkType = true;
    if (tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_UNKNOWN && !networkInfo.isConnected()) {
        networkType = false;
    }

    Log.d("Phone state before if statement", "Phone State: " + mServiceState);
    Log.e("network isavailable", String.valueOf(networkInfo.isAvailable()));
    if (!networkType || !mLocationManager.isProviderEnabled("network")) {
        networkAvailable = false;
    }

    try {
        Log.e("Location_mode", String.valueOf(
                Settings.Secure.getInt(getActivity().getContentResolver(), Settings.Secure.LOCATION_MODE)));
        locationMode = Settings.Secure.getInt(getActivity().getContentResolver(),
                Settings.Secure.LOCATION_MODE);
    } catch (SettingNotFoundException e) {
        oldApi = true;
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    if ((oldApi && mProvider.matches("passive")) || locationMode == LOCATION_MODE_OFF || (!networkAvailable
            && (mProvider.matches("network") || (!gpsPref && mProvider.matches("gps"))))) {
        builder.setTitle(getString(R.string.dialog_location_no_location_services_title));
        builder.setMessage(getString(R.string.dialog_location_no_location_services_message));
        builder.setNeutralButton(R.string.dialog_location_button_settings, noNetworkButton);
        mAbortRequest = true;
    } else if ((oldApi && mProvider.matches("gps") && gpsPref) || (mProvider.matches("gps") && gpsPref
            && (locationMode == LOCATION_MODE_SENSORS_ONLY || locationMode == LOCATION_MODE_HIGH_ACCURACY))) {
        if (mTypeFrag == NOTE_EDIT) {
            builder.setTitle(getString(R.string.dialog_location_finding_note_gps));
        } else if (mTypeFrag == NOTE_LIST) {
            builder.setTitle(getString(R.string.dialog_location_updating_note_gps));
        }
        if (locationMode == LOCATION_MODE_SENSORS_ONLY || (oldApi && mProvider.matches("gps"))
                || !networkAvailable) {
            builder.setMessage(getString(R.string.dialog_location_only_gps_message));
            builder.setNeutralButton(R.string.dialog_location_button_settings, noNetworkButton);

        } else
            builder.setPositiveButton(R.string.dialog_location_use_network, null);

        builder.setView(getActivity().getLayoutInflater().inflate(R.layout.dialogue_location, null));

    } else if ((oldApi && mProvider.matches("network")) || (mProvider.matches("network")
            && (locationMode == LOCATION_MODE_BATTERY_SAVING || locationMode == LOCATION_MODE_HIGH_ACCURACY))) {
        builder.setView(getActivity().getLayoutInflater().inflate(R.layout.dialogue_location, null));
        if (mTypeFrag == NOTE_EDIT) {
            builder.setTitle(getString(R.string.dialog_location_finding_note_network));
        } else if (mTypeFrag == NOTE_LIST) {
            builder.setTitle(getString(R.string.dialog_location_updating_note_network));
        }

    }
    builder.setNegativeButton(R.string.cancel, cancelListener);
    // Create the AlertDialog object and return it

    // builder.create();

    builder.setOnKeyListener(new DialogInterface.OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                mCallback.onLocationFound(null, mTypeFrag);
                mLocationManager.removeUpdates(NoteLocation.this);
                Toast.makeText(getActivity(), "Location request cancelled", Toast.LENGTH_SHORT).show();
                dialog.cancel();
                return true;
            }

            return false;
        }
    });

    mRealDialog = builder.create();
    // final LocationListener getFragment() = this.;

    mRealDialog.setOnShowListener(usingNetwork);
    mRealDialog.setCanceledOnTouchOutside(false);
    // mRealDialog.setCancelable(false);
    return mRealDialog;

}

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

public static String getGeneralInfo(Context context) {
    StringBuilder sb = new StringBuilder();
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append(String.format("Interactive %B\r\n", isInteractive(context)));
    sb.append(String.format("Connected %B\r\n", isConnected(context)));
    sb.append(String.format("WiFi %B\r\n", isWifiActive(context)));
    sb.append(String.format("Metered %B\r\n", isMeteredNetwork(context)));
    sb.append(String.format("Roaming %B\r\n", isRoaming(context)));

    if (tm.getSimState() == TelephonyManager.SIM_STATE_READY)
        sb.append(String.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(),
                tm.getSimOperator()));/*from   w  ww.j a  v  a 2  s  . co  m*/
    if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN)
        sb.append(String.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(), tm.getNetworkOperatorName(),
                tm.getNetworkOperator()));

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode()));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        sb.append(String.format("Battery optimizing %B\r\n", batteryOptimizing(context)));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        sb.append(String.format("Data saving %B\r\n", dataSaving(context)));

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}

From source file:fr.inria.ucn.collectors.NetworkStateCollector.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private JSONObject getMobile(TelephonyManager tm) throws JSONException {
    JSONObject mob = new JSONObject();

    mob.put("call_state", tm.getCallState());
    mob.put("data_activity", tm.getDataActivity());
    mob.put("network_type", tm.getNetworkType());
    mob.put("network_type_str", Helpers.getTelephonyNetworkType(tm.getNetworkType()));
    mob.put("phone_type", tm.getPhoneType());
    mob.put("phone_type_str", Helpers.getTelephonyPhoneType(tm.getPhoneType()));
    mob.put("sim_state", tm.getSimState());
    mob.put("network_country", tm.getNetworkCountryIso());
    mob.put("network_operator", tm.getNetworkOperator());
    mob.put("network_operator_name", tm.getNetworkOperatorName());

    // current cell location
    CellLocation cl = tm.getCellLocation();
    if (cl != null) {
        JSONObject loc = new JSONObject();
        if (cl instanceof GsmCellLocation) {
            JSONObject cell = new JSONObject();
            cell.put("cid", ((GsmCellLocation) cl).getCid());
            cell.put("lac", ((GsmCellLocation) cl).getLac());
            cell.put("psc", ((GsmCellLocation) cl).getPsc());
            loc.put("gsm", cell);
        } else if (cl instanceof CdmaCellLocation) {
            JSONObject cell = new JSONObject();
            cell.put("bs_id", ((CdmaCellLocation) cl).getBaseStationId());
            cell.put("bs_lat", ((CdmaCellLocation) cl).getBaseStationLatitude());
            cell.put("bs_lon", ((CdmaCellLocation) cl).getBaseStationLongitude());
            cell.put("net_id", ((CdmaCellLocation) cl).getNetworkId());
            cell.put("sys_id", ((CdmaCellLocation) cl).getSystemId());
            loc.put("cdma", cell);
        }/*from  ww w.j a  v  a  2 s  . c  om*/
        mob.put("cell_location", loc);
    }

    // Cell neighbors
    List<NeighboringCellInfo> ncl = tm.getNeighboringCellInfo();
    if (ncl != null) {
        JSONArray cells = new JSONArray();
        for (NeighboringCellInfo nc : ncl) {
            JSONObject jnc = new JSONObject();
            jnc.put("cid", nc.getCid());
            jnc.put("lac", nc.getLac());
            jnc.put("network_type", nc.getNetworkType());
            jnc.put("network_type_str", Helpers.getTelephonyNetworkType(nc.getNetworkType()));
            jnc.put("psc", nc.getPsc());
            jnc.put("rssi", nc.getRssi());
            cells.put(jnc);
        }
        mob.put("neigh_cells", cells);
    }

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // only works for API level >=17
        List<CellInfo> aci = (List<CellInfo>) tm.getAllCellInfo();
        if (aci != null) {
            JSONArray cells = new JSONArray();
            for (CellInfo ci : aci) {
                JSONObject jci = new JSONObject();
                if (ci instanceof CellInfoGsm) {
                    CellInfoGsm cigsm = (CellInfoGsm) ci;
                    jci.put("is_registered", cigsm.isRegistered());
                    jci.put("type", "gsm");
                    jci.put("cid", cigsm.getCellIdentity().getCid());
                    jci.put("lac", cigsm.getCellIdentity().getLac());
                    jci.put("mcc", cigsm.getCellIdentity().getMcc());
                    jci.put("mnc", cigsm.getCellIdentity().getMnc());
                    jci.put("psc", cigsm.getCellIdentity().getPsc());

                    jci.put("asu_level", cigsm.getCellSignalStrength().getAsuLevel());
                    jci.put("level", cigsm.getCellSignalStrength().getLevel());
                    jci.put("dbm", cigsm.getCellSignalStrength().getDbm());

                } else if (ci instanceof CellInfoCdma) {
                    CellInfoCdma cicdma = (CellInfoCdma) ci;
                    jci.put("is_registered", cicdma.isRegistered());
                    jci.put("type", "cdma");
                    jci.put("bs_id", cicdma.getCellIdentity().getBasestationId());
                    jci.put("bs_lat", cicdma.getCellIdentity().getLatitude());
                    jci.put("bs_lon", cicdma.getCellIdentity().getLongitude());
                    jci.put("net_id", cicdma.getCellIdentity().getNetworkId());
                    jci.put("sys_id", cicdma.getCellIdentity().getSystemId());

                    jci.put("asu_level", cicdma.getCellSignalStrength().getAsuLevel());
                    jci.put("dbm", cicdma.getCellSignalStrength().getDbm());
                    jci.put("level", cicdma.getCellSignalStrength().getLevel());
                    jci.put("cdma_dbm", cicdma.getCellSignalStrength().getCdmaDbm());
                    jci.put("cdma_ecio", cicdma.getCellSignalStrength().getCdmaEcio());
                    jci.put("cdma_level", cicdma.getCellSignalStrength().getCdmaLevel());
                    jci.put("evdo_dbm", cicdma.getCellSignalStrength().getEvdoDbm());
                    jci.put("evdo_ecio", cicdma.getCellSignalStrength().getEvdoEcio());
                    jci.put("evdo_level", cicdma.getCellSignalStrength().getEvdoLevel());
                    jci.put("evdo_snr", cicdma.getCellSignalStrength().getEvdoSnr());

                } else if (ci instanceof CellInfoWcdma) {
                    CellInfoWcdma ciwcdma = (CellInfoWcdma) ci;
                    jci.put("is_registered", ciwcdma.isRegistered());
                    jci.put("type", "wcdma");
                    jci.put("cid", ciwcdma.getCellIdentity().getCid());
                    jci.put("lac", ciwcdma.getCellIdentity().getLac());
                    jci.put("mcc", ciwcdma.getCellIdentity().getMcc());
                    jci.put("mnc", ciwcdma.getCellIdentity().getMnc());
                    jci.put("psc", ciwcdma.getCellIdentity().getPsc());

                    jci.put("asu_level", ciwcdma.getCellSignalStrength().getAsuLevel());
                    jci.put("dbm", ciwcdma.getCellSignalStrength().getDbm());
                    jci.put("level", ciwcdma.getCellSignalStrength().getLevel());

                } else if (ci instanceof CellInfoLte) {
                    CellInfoLte cilte = (CellInfoLte) ci;
                    jci.put("is_registered", cilte.isRegistered());
                    jci.put("type", "lte");
                    jci.put("ci", cilte.getCellIdentity().getCi());
                    jci.put("mcc", cilte.getCellIdentity().getMcc());
                    jci.put("mnc", cilte.getCellIdentity().getMnc());
                    jci.put("pci", cilte.getCellIdentity().getPci());
                    jci.put("tac", cilte.getCellIdentity().getTac());

                    jci.put("asu_level", cilte.getCellSignalStrength().getAsuLevel());
                    jci.put("dbm", cilte.getCellSignalStrength().getDbm());
                    jci.put("level", cilte.getCellSignalStrength().getLevel());
                    jci.put("timing_adv", cilte.getCellSignalStrength().getTimingAdvance());

                }
                cells.put(jci);
            }
            mob.put("all_cells", cells);
        }
    }
    return mob;
}

From source file:com.master.metehan.filtereagle.Util.java

public static String getGeneralInfo(Context context) {
    StringBuilder sb = new StringBuilder();
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append(String.format("Interactive %B\r\n", isInteractive(context)));
    sb.append(String.format("Connected %B\r\n", isConnected(context)));
    sb.append(String.format("WiFi %B\r\n", isWifiActive(context)));
    sb.append(String.format("Metered %B\r\n", isMeteredNetwork(context)));
    sb.append(String.format("Roaming %B\r\n", isRoaming(context)));

    sb.append(String.format("Type %s\r\n", getPhoneTypeName(tm.getPhoneType())));

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1 || !hasPhoneStatePermission(context)) {
        if (tm.getSimState() == TelephonyManager.SIM_STATE_READY)
            sb.append(String.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(),
                    tm.getSimOperator()));
        if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN)
            sb.append(String.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(),
                    tm.getNetworkOperatorName(), tm.getNetworkOperator()));
    }/*from w ww .  ja  v  a 2s . c  o m*/

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode()));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        sb.append(String.format("Battery optimizing %B\r\n",
                !pm.isIgnoringBatteryOptimizations(context.getPackageName())));

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}