Recuperar información de torres de celdas
¿Alguien sabe cómo recuperar la lista de torre celular en GSM y CDMA en Android.
He estado intentando utilizar la API de ubicaciones de Google Maps: https://developers.google.com/maps/documentation/business/geolocation/
Y quiero obtener información sobre torres de celdas con estos campos:
- CellId: identificador único de la celda. En GSM, este es el ID de celda (CID); Las redes CDMA utilizan el ID de estación base (BID).
- LocationAreaCode: El código de área de ubicación (LAC) para redes GSM; Las redes CDMA utilizan ID de red (NID).
- MobileCountryCode: El código de país móvil de la torre celular (MCC).
- MobileNetworkCode: Código de red móvil de la torre celular. Este es el MNC para GSM o el ID de sistema (SID) para CDMA.
- Age: El número de milisegundos desde que esta celda fue primaria. Si la edad es 0, el cellId representa una medida actual.
- SignalStrength: intensidad de la señal de radio medida en dBm.
- TimingAdvance: El valor de avance de tiempo.
Este código no obtiene especialmente información de torres de celda.
TelephonyManager tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); // Type of the network int phoneTypeInt = tel.getPhoneType(); String phoneType = null; phoneType = phoneTypeInt == TelephonyManager.PHONE_TYPE_GSM ? "gsm" : phoneType; phoneType = phoneTypeInt == TelephonyManager.PHONE_TYPE_CDMA ? "cdma" : phoneType; try { if (phoneType != null) { params.put("radioType", phoneType); } } catch (Exception e) {} /* * The below code doesn't work I think. */ JSONArray cellList = new JSONArray(); List<NeighboringCellInfo> neighCells = tel.getNeighboringCellInfo(); for (int i = 0; i < neighCells.size(); i++) { try { JSONObject cellObj = new JSONObject(); NeighboringCellInfo thisCell = neighCells.get(i); cellObj.put("cellId", thisCell.getCid()); cellList.put(cellObj); } catch (Exception e) {} } if (cellList.length() > 0) { try { params.put("cellTowers", cellList); } catch (JSONException e) {} }
Y establezco permisos como este:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/> <uses-permission android:name="android.permission.INTERNET"/>
Por favor, ayúdame, gracias.
Es posible que su teléfono no admita esta función.
Consulte esto: http://code.google.com/p/android/issues/detail?id=24136
Y esto: ¿Qué modelos de teléfonos Android admiten getNeighboringCellInfo ()?
Tuve este problema mucho más recientemente y terminó siendo el hecho de que
GetNeighboringCellInfo
Está obsoleto de la API 23. Para evitar este uso algo como lo siguiente (es bastante molesto, realmente):
public static JSONArray getCellInfo(Context ctx){ TelephonyManager tel = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); JSONArray cellList = new JSONArray(); // Type of the network int phoneTypeInt = tel.getPhoneType(); String phoneType = null; phoneType = phoneTypeInt == TelephonyManager.PHONE_TYPE_GSM ? "gsm" : phoneType; phoneType = phoneTypeInt == TelephonyManager.PHONE_TYPE_CDMA ? "cdma" : phoneType; //from Android M up must use getAllCellInfo if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { List<NeighboringCellInfo> neighCells = tel.getNeighboringCellInfo(); for (int i = 0; i < neighCells.size(); i++) { try { JSONObject cellObj = new JSONObject(); NeighboringCellInfo thisCell = neighCells.get(i); cellObj.put("cellId", thisCell.getCid()); cellObj.put("lac", thisCell.getLac()); cellObj.put("rssi", thisCell.getRssi()); cellList.put(cellObj); } catch (Exception e) { } } } else { List<CellInfo> infos = tel.getAllCellInfo(); for (int i = 0; i<infos.size(); ++i) { try { JSONObject cellObj = new JSONObject(); CellInfo info = infos.get(i); if (info instanceof CellInfoGsm){ CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength(); CellIdentityGsm identityGsm = ((CellInfoGsm) info).getCellIdentity(); cellObj.put("cellId", identityGsm.getCid()); cellObj.put("lac", identityGsm.getLac()); cellObj.put("dbm", gsm.getDbm()); cellList.put(cellObj); } else if (info instanceof CellInfoLte) { CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength(); CellIdentityLte identityLte = ((CellInfoLte) info).getCellIdentity(); cellObj.put("cellId", identityLte.getCi()); cellObj.put("tac", identityLte.getTac()); cellObj.put("dbm", lte.getDbm()); cellList.put(cellObj); } } catch (Exception ex) { } } } return cellList; }
No es su teléfono, que no es compatible con esta información, es la implementación puramente malo de la RIL relacionados C y Java utilizados para proporcionar esas llamadas API, que impiden esto. Si usted consigue entrar en los menús del Service Mode
(que varían ampliamente de teléfono a teléfono) tendrá acceso completo e instantáneo a RSSI y cargas de otros tipos de señales. Usted debe culpar a Google (o su OEM) por no solucionar esos problemas y proporcionar un mejor acceso a RF variables relacionadas.