Exemplo n.º 1
0
 @Override
 public void onCellInfoChanged(List<CellInfo> cellInfo) {
   CellLocationInfo.Params p;
   List<CellLocationInfo> cells = new ArrayList<CellLocationInfo>(cellInfo.size());
   for (CellInfo info : cellInfo) {
     p = new CellLocationInfo.Params();
     p.time = info.getTimeStamp();
     if (info instanceof CellInfoCdma) {
       CellInfoCdma cdma = (CellInfoCdma) info;
       p.id = cdma.getCellIdentity().getBasestationId();
       p.lat = cdma.getCellIdentity().getLatitude();
       p.lon = cdma.getCellIdentity().getLongitude();
       p.dbm = cdma.getCellSignalStrength().getDbm(); // there's two other dbm methods
       p.asu = cdma.getCellSignalStrength().getAsuLevel();
     } else if (info instanceof CellInfoGsm) {
       CellInfoGsm gsm = (CellInfoGsm) info;
       p.id = gsm.getCellIdentity().getCid();
       p.dbm = gsm.getCellSignalStrength().getDbm();
       p.asu = gsm.getCellSignalStrength().getAsuLevel();
     } else if (info instanceof CellInfoLte) {
       CellInfoLte lte = (CellInfoLte) info;
       p.id = lte.getCellIdentity().getCi();
       p.dbm = lte.getCellSignalStrength().getDbm();
       p.asu = lte.getCellSignalStrength().getAsuLevel();
     } else if (info instanceof CellInfoWcdma) {
       CellInfoWcdma wcdma = (CellInfoWcdma) info;
       p.id = wcdma.getCellIdentity().getCid();
       p.dbm = wcdma.getCellSignalStrength().getDbm();
       p.asu = wcdma.getCellSignalStrength().getAsuLevel();
     }
     cells.add(new CellLocationInfo(p));
   }
   cellInfos = cells.toArray(new CellLocationInfo[cells.size()]);
   notifyListeners(EVENT_CELL_INFOS);
 }
  private String getSignalStrength() {
    TelephonyManager telephonyManager =
        (TelephonyManager) getSystemService(getApplicationContext().TELEPHONY_SERVICE);
    List<CellInfo> cellInfoList = telephonyManager.getAllCellInfo();

    if (((TextView) findViewById(R.id.connectionTypeTextView)).getText().toString().equals("3G")) {
      return Integer.toString(threeGSignalStrength);
    }

    for (int i = 0; i < cellInfoList.size(); i++) {
      CellInfo ci = cellInfoList.get(i);

      if (ci instanceof CellInfoCdma) {
        CellInfoCdma cdmaCellInfo = (CellInfoCdma) ci;
        CellSignalStrengthCdma cdmaSignalStrength = cdmaCellInfo.getCellSignalStrength();
        return Integer.toString(cdmaSignalStrength.getDbm());
      } else if (ci instanceof CellInfoLte) {
        CellInfoLte lteCellInfo = (CellInfoLte) ci;
        CellSignalStrengthLte lteSignalStrength = lteCellInfo.getCellSignalStrength();
        return Integer.toString(lteSignalStrength.getDbm());
      } else {
        return "Error: bad cell info";
      }
    }

    return "Error: no cell info";
  }
  /**
   * Retrieves the tower ID, network type, RSS, and timestamp for a CDMA cell.
   *
   * @param info
   * @return
   */
  private CellularInfo processCdmaInfo(CellInfoCdma info) {
    int id = info.getCellIdentity().getBasestationId();
    int asu = info.getCellSignalStrength().getAsuLevel();
    int rss = info.getCellSignalStrength().getDbm();
    String type = CellularInfo.TYPE_CDMA;

    // RSS can not always be obtained
    String strRss = (asu == 99 || rss > 100 || rss < -200) ? "N/A" : Integer.toString(rss);

    if (id < 0) return null;

    return new CellularInfo(Integer.toString(id), type, strRss, Utils.getTimestamp());
  }
Exemplo n.º 4
0
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
 public Tower(CellInfoCdma cellInfoCdma) {
   setLocationAreaCode(cellInfoCdma.getCellIdentity().getNetworkId());
   setCellId(cellInfoCdma.getCellIdentity().getSystemId());
   setSignalStrength(cellInfoCdma.getCellSignalStrength().getLevel());
   setRssi(cellInfoCdma.getCellSignalStrength().getCdmaDbm());
   setPrimaryScrambleCode(cellInfoCdma.getCellIdentity().getSystemId());
   setNetworkType(cellInfoCdma.getCellIdentity().getBasestationId());
   setLatLng(
       new LatLng(
           cellInfoCdma.getCellIdentity().getLatitude(),
           cellInfoCdma.getCellIdentity().getLongitude()));
   setTime(GeneralUtils.getCurrentTime());
   setNeighbor(false);
 }