android.telephony.CellSignalStrengthCdma Java Examples

The following examples show how to use android.telephony.CellSignalStrengthCdma. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CellInfoCdmaAssert.java    From assertj-android with Apache License 2.0 5 votes vote down vote up
public CellInfoCdmaAssert hasCellSignalStrength(CellSignalStrengthCdma cellSignalStrength) {
  isNotNull();
  CellSignalStrengthCdma actualCellSignalStrength = actual.getCellSignalStrength();
  assertThat(actualCellSignalStrength) //
      .overridingErrorMessage("Expected cell signal strength <%s> but was <%s>.", cellSignalStrength, actualCellSignalStrength) //
      .isEqualTo(cellSignalStrength);
  return this;
}
 
Example #2
Source File: Net.java    From HttpInfo with Apache License 2.0 4 votes vote down vote up
public static void getMobileDbm(Context context, NetBean netBean) {
    int dbm = 0;
    int level = 0;
    int asu = 0;
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        List<CellInfo> cellInfoList;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            if (tm == null) {
                return;
            }
            cellInfoList = tm.getAllCellInfo();
            if (null != cellInfoList) {
                for (CellInfo cellInfo : cellInfoList) {
                    if (cellInfo instanceof CellInfoGsm) {
                        CellSignalStrengthGsm cellSignalStrengthGsm = ((CellInfoGsm) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthGsm.getDbm();
                        level = cellSignalStrengthGsm.getLevel();
                        asu = cellSignalStrengthGsm.getAsuLevel();
                    } else if (cellInfo instanceof CellInfoCdma) {
                        CellSignalStrengthCdma cellSignalStrengthCdma =
                                ((CellInfoCdma) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthCdma.getDbm();
                        level = cellSignalStrengthCdma.getLevel();
                        asu = cellSignalStrengthCdma.getAsuLevel();
                    } else if (cellInfo instanceof CellInfoLte) {
                        CellSignalStrengthLte cellSignalStrengthLte = ((CellInfoLte) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthLte.getDbm();
                        level = cellSignalStrengthLte.getLevel();
                        asu = cellSignalStrengthLte.getAsuLevel();
                    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                        if (cellInfo instanceof CellInfoWcdma) {
                            CellSignalStrengthWcdma cellSignalStrengthWcdma =
                                    ((CellInfoWcdma) cellInfo).getCellSignalStrength();
                            dbm = cellSignalStrengthWcdma.getDbm();
                            level = cellSignalStrengthWcdma.getLevel();
                            asu = cellSignalStrengthWcdma.getAsuLevel();
                        }
                    }
                }
            }
        }

    } catch (Exception e) {
        HttpLog.e("signal info:" + e.toString());
    }
    netBean.setMobAsu(asu);
    netBean.setMobDbm(dbm);
    netBean.setMobLevel(level);
}
 
Example #3
Source File: SignalInfo.java    From MobileInfo with Apache License 2.0 4 votes vote down vote up
/**
 * mobile
 *
 * @param context
 * @return
 */
@SuppressLint("MissingPermission")
private static void getMobileDbm(Context context, SignalBean signalBean) {
    int dbm = -1;
    int level = 0;
    try {
        signalBean.setnIpAddress(getNetIPV4());
        signalBean.setnIpAddressIpv6(getNetIP());
        signalBean.setMacAddress(getMac(context));
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        List<CellInfo> cellInfoList;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            if (tm == null) {
                return;
            }
            cellInfoList = tm.getAllCellInfo();
            if (null != cellInfoList) {
                for (CellInfo cellInfo : cellInfoList) {
                    if (cellInfo instanceof CellInfoGsm) {
                        CellSignalStrengthGsm cellSignalStrengthGsm = ((CellInfoGsm) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthGsm.getDbm();
                        level = cellSignalStrengthGsm.getLevel();
                    } else if (cellInfo instanceof CellInfoCdma) {
                        CellSignalStrengthCdma cellSignalStrengthCdma =
                                ((CellInfoCdma) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthCdma.getDbm();
                        level = cellSignalStrengthCdma.getLevel();
                    } else if (cellInfo instanceof CellInfoLte) {
                        CellSignalStrengthLte cellSignalStrengthLte = ((CellInfoLte) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthLte.getDbm();
                        level = cellSignalStrengthLte.getLevel();

                    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                        if (cellInfo instanceof CellInfoWcdma) {
                            CellSignalStrengthWcdma cellSignalStrengthWcdma =
                                    ((CellInfoWcdma) cellInfo).getCellSignalStrength();
                            dbm = cellSignalStrengthWcdma.getDbm();
                            level = cellSignalStrengthWcdma.getLevel();
                        }
                    }
                }
            }
        }
        signalBean.setRssi(dbm );
        signalBean.setLevel(level);
    } catch (Exception e) {
        Log.i(TAG, e.toString());
    }
}
 
Example #4
Source File: DeviceApi17.java    From AIMSICDL with GNU General Public License v3.0 4 votes vote down vote up
public static void loadCellInfo(TelephonyManager tm, Device pDevice) {
    int lCurrentApiVersion = android.os.Build.VERSION.SDK_INT;
    try {
        if (pDevice.mCell == null) {
            pDevice.mCell = new Cell();
        }
        List<CellInfo> cellInfoList = tm.getAllCellInfo();
        if (cellInfoList != null) {
            for (final CellInfo info : cellInfoList) {

                //Network Type
                pDevice.mCell.setNetType(tm.getNetworkType());

                if (info instanceof CellInfoGsm) {
                    final CellSignalStrengthGsm gsm = ((CellInfoGsm) info)
                            .getCellSignalStrength();
                    final CellIdentityGsm identityGsm = ((CellInfoGsm) info)
                            .getCellIdentity();
                    //Signal Strength
                    pDevice.mCell.setDBM(gsm.getDbm()); // [dBm]
                    //Cell Identity
                    pDevice.mCell.setCID(identityGsm.getCid());
                    pDevice.mCell.setMCC(identityGsm.getMcc());
                    pDevice.mCell.setMNC(identityGsm.getMnc());
                    pDevice.mCell.setLAC(identityGsm.getLac());

                } else if (info instanceof CellInfoCdma) {
                    final CellSignalStrengthCdma cdma = ((CellInfoCdma) info)
                            .getCellSignalStrength();
                    final CellIdentityCdma identityCdma = ((CellInfoCdma) info)
                            .getCellIdentity();
                    //Signal Strength
                    pDevice.mCell.setDBM(cdma.getDbm());
                    //Cell Identity
                    pDevice.mCell.setCID(identityCdma.getBasestationId());
                    pDevice.mCell.setMNC(identityCdma.getSystemId());
                    pDevice.mCell.setLAC(identityCdma.getNetworkId());
                    pDevice.mCell.setSID(identityCdma.getSystemId());

                } else if (info instanceof CellInfoLte) {
                    final CellSignalStrengthLte lte = ((CellInfoLte) info)
                            .getCellSignalStrength();
                    final CellIdentityLte identityLte = ((CellInfoLte) info)
                            .getCellIdentity();
                    //Signal Strength
                    pDevice.mCell.setDBM(lte.getDbm());
                    pDevice.mCell.setTimingAdvance(lte.getTimingAdvance());
                    //Cell Identity
                    pDevice.mCell.setMCC(identityLte.getMcc());
                    pDevice.mCell.setMNC(identityLte.getMnc());
                    pDevice.mCell.setCID(identityLte.getCi());

                } else if  (lCurrentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2 &&
                        info instanceof CellInfoWcdma) {
                    final CellSignalStrengthWcdma wcdma = ((CellInfoWcdma) info)
                            .getCellSignalStrength();
                    final CellIdentityWcdma identityWcdma = ((CellInfoWcdma) info)
                            .getCellIdentity();
                    //Signal Strength
                    pDevice.mCell.setDBM(wcdma.getDbm());
                    //Cell Identity
                    pDevice.mCell.setLAC(identityWcdma.getLac());
                    pDevice.mCell.setMCC(identityWcdma.getMcc());
                    pDevice.mCell.setMNC(identityWcdma.getMnc());
                    pDevice.mCell.setCID(identityWcdma.getCid());
                    pDevice.mCell.setPSC(identityWcdma.getPsc());

                } else {
                    Log.i(TAG, mTAG + "Unknown type of cell signal! "
                            + "ClassName: " + info.getClass().getSimpleName()
                            + " ToString: " + info.toString());
                }
                if (pDevice.mCell.isValid()) {
                    break;
                }
            }
        }
    } catch (NullPointerException npe) {
       Log.e(TAG, mTAG + "loadCellInfo: Unable to obtain cell signal information: ", npe);
    }

}
 
Example #5
Source File: DeviceApi18.java    From AIMSICDL with GNU General Public License v3.0 4 votes vote down vote up
public static void loadCellInfo(TelephonyManager tm, Device pDevice) {
    int lCurrentApiVersion = android.os.Build.VERSION.SDK_INT;
    try {
        if (pDevice.mCell == null) {
            pDevice.mCell = new Cell();
        }
        List<CellInfo> cellInfoList = tm.getAllCellInfo();
        if (cellInfoList != null) {
            for (final CellInfo info : cellInfoList) {

                //Network Type
                pDevice.mCell.setNetType(tm.getNetworkType());

                if (info instanceof CellInfoGsm) {
                    final CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();
                    final CellIdentityGsm identityGsm = ((CellInfoGsm) info).getCellIdentity();
                    // Signal Strength
                    pDevice.mCell.setDBM(gsm.getDbm()); // [dBm]
                    // Cell Identity
                    pDevice.mCell.setCID(identityGsm.getCid());
                    pDevice.mCell.setMCC(identityGsm.getMcc());
                    pDevice.mCell.setMNC(identityGsm.getMnc());
                    pDevice.mCell.setLAC(identityGsm.getLac());

                } else if (info instanceof CellInfoCdma) {
                    final CellSignalStrengthCdma cdma = ((CellInfoCdma) info).getCellSignalStrength();
                    final CellIdentityCdma identityCdma = ((CellInfoCdma) info).getCellIdentity();
                    // Signal Strength
                    pDevice.mCell.setDBM(cdma.getDbm());
                    // Cell Identity
                    pDevice.mCell.setCID(identityCdma.getBasestationId());
                    pDevice.mCell.setMNC(identityCdma.getSystemId());
                    pDevice.mCell.setLAC(identityCdma.getNetworkId());
                    pDevice.mCell.setSID(identityCdma.getSystemId());

                } else if (info instanceof CellInfoLte) {
                    final CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();
                    final CellIdentityLte identityLte = ((CellInfoLte) info).getCellIdentity();
                    // Signal Strength
                    pDevice.mCell.setDBM(lte.getDbm());
                    pDevice.mCell.setTimingAdvance(lte.getTimingAdvance());
                    // Cell Identity
                    pDevice.mCell.setMCC(identityLte.getMcc());
                    pDevice.mCell.setMNC(identityLte.getMnc());
                    pDevice.mCell.setCID(identityLte.getCi());

                } else if  (lCurrentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2 && info instanceof CellInfoWcdma) {
                    final CellSignalStrengthWcdma wcdma = ((CellInfoWcdma) info).getCellSignalStrength();
                    final CellIdentityWcdma identityWcdma = ((CellInfoWcdma) info).getCellIdentity();
                    // Signal Strength
                    pDevice.mCell.setDBM(wcdma.getDbm());
                    // Cell Identity
                    pDevice.mCell.setLAC(identityWcdma.getLac());
                    pDevice.mCell.setMCC(identityWcdma.getMcc());
                    pDevice.mCell.setMNC(identityWcdma.getMnc());
                    pDevice.mCell.setCID(identityWcdma.getCid());
                    pDevice.mCell.setPSC(identityWcdma.getPsc());

                } else {
                    Log.i(TAG, mTAG + "Unknown type of cell signal!"
                            + "\n ClassName: " + info.getClass().getSimpleName()
                            + "\n ToString: " + info.toString());
                }
                if (pDevice.mCell.isValid()) {
                    break;
                }
            }
        }
    } catch (NullPointerException npe) {
       Log.e(TAG, mTAG + "loadCellInfo: Unable to obtain cell signal information: ", npe);
    }
}
 
Example #6
Source File: JSONHelper.java    From cordova-plugin-advanced-geolocation with Apache License 2.0 4 votes vote down vote up
/**
 * Converts CellInfoCdma into JSON
 * @param cellInfo CellInfoCdma
 * @return JSON
 */
public static String cellInfoCDMAJSON(CellInfoCdma cellInfo, boolean returnSignalStrength){

    final Calendar calendar = Calendar.getInstance();
    final JSONObject json = new JSONObject();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && cellInfo != null) {
        try {
            json.put("provider", CELLINFO_PROVIDER);
            json.put("type", CDMA);
            json.put("timestamp", calendar.getTimeInMillis());

            final CellIdentityCdma identityCdma = cellInfo.getCellIdentity();

            json.put("latitude", CdmaCellLocation.convertQuartSecToDecDegrees(identityCdma.getLatitude()));
            json.put("longitude", CdmaCellLocation.convertQuartSecToDecDegrees(identityCdma.getLongitude()));
            json.put("basestationId", identityCdma.getBasestationId());
            json.put("networkId", identityCdma.getNetworkId());
            json.put("systemId", identityCdma.getSystemId());

            if (returnSignalStrength){
                final JSONObject jsonSignalStrength = new JSONObject();
                final CellSignalStrengthCdma cellSignalStrengthCdma = cellInfo.getCellSignalStrength();
                jsonSignalStrength.put("asuLevel", cellSignalStrengthCdma.getAsuLevel());
                jsonSignalStrength.put("cdmaDbm", cellSignalStrengthCdma.getCdmaDbm());
                jsonSignalStrength.put("cdmaEcio", cellSignalStrengthCdma.getCdmaEcio());
                jsonSignalStrength.put("cdmaLevel", cellSignalStrengthCdma.getCdmaLevel());
                jsonSignalStrength.put("dbm", cellSignalStrengthCdma.getDbm());
                jsonSignalStrength.put("evdoDbm", cellSignalStrengthCdma.getEvdoDbm());
                jsonSignalStrength.put("evdoEcio", cellSignalStrengthCdma.getEvdoEcio());
                jsonSignalStrength.put("evdoLevel", cellSignalStrengthCdma.getEvdoLevel());
                jsonSignalStrength.put("evdoSnr", cellSignalStrengthCdma.getEvdoSnr());
                jsonSignalStrength.put("level", cellSignalStrengthCdma.getLevel());

                json.put("cellSignalStrengthCdma", jsonSignalStrength);
            }
        }
        catch(JSONException exc) {
            logJSONException(exc);
        }
    }

    return json.toString();
}
 
Example #7
Source File: CellularDrawer.java    From meter with Apache License 2.0 4 votes vote down vote up
public CellularDrawer(final Context context){
    super(
            context,
            context.getResources().getColor(R.color.cellular_background),
            context.getResources().getColor(R.color.cellular_triangle_background),
            context.getResources().getColor(R.color.cellular_triangle_foreground),
            context.getResources().getColor(R.color.cellular_triangle_critical)
    );

    this.label1 = "Cellular";

    tManager = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
    setLabel2();

    tManager.listen(new PhoneStateListener(){
        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            super.onSignalStrengthsChanged(signalStrength);

            int level = 0;
            String tech = "";

            if( isAirplaneModeOn(context) ){
                percent = 0f;
                connected = false;
                label1 = "No connection";
                label2 = "Airplane Mode Enabled";
                return;
            }

            List<CellInfo> infos = null;

            try {
                infos = tManager.getAllCellInfo();
            } catch (SecurityException e){
                Log.e(TAG, e.toString());
            }

            if( infos == null ){
                connected = false;
                return;
            }

            for (final CellInfo info : infos) {
                if (info instanceof CellInfoWcdma) {
                    final CellSignalStrengthWcdma  wcdma = ((CellInfoWcdma) info).getCellSignalStrength();

                    if(level < wcdma.getLevel()) {
                        level = wcdma.getLevel();
                        tech = "wcdma";
                    }
                } else if (info instanceof CellInfoGsm) {
                    final CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();

                    if(level < gsm.getLevel()) {
                        level = gsm.getLevel();
                        tech = "gsm";
                    }
                } else if (info instanceof CellInfoCdma) {
                    final CellSignalStrengthCdma cdma = ((CellInfoCdma) info).getCellSignalStrength();

                    if(level < cdma.getLevel()) {
                        level = cdma.getLevel();
                        tech = "cdma";
                    }
                } else if (info instanceof CellInfoLte) {
                    final CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();

                    if(level < lte.getLevel()) {
                        level = lte.getLevel();
                        tech = "lte";
                    }

                }
            }

            connected = true;
            label1 = "Cellular";
            percent = (float) (level / 4.0);

            if (firstRead) {
                firstRead = false;
                _percent = (float) (percent - 0.001);
            }
        }

        @Override
        public void onServiceStateChanged(ServiceState serviceState) {
            super.onServiceStateChanged(serviceState);
            setLabel2();
            Log.d(TAG,"STATE "+String.valueOf(serviceState)+"   "+serviceState.getState());
        }
    },PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_SERVICE_STATE);

}
 
Example #8
Source File: CellSignalStrengthCdmaAssert.java    From assertj-android with Apache License 2.0 4 votes vote down vote up
public CellSignalStrengthCdmaAssert(CellSignalStrengthCdma actual) {
  super(actual, CellSignalStrengthCdmaAssert.class);
}