Does anybody know how to retrieve cell tower list on GSM and CDMA on Android.
I have been trying to use Google Maps Locations API:
https://developers.google.com/maps/documentation/business/geolocation/
And I want to get cell towers information with these fields:
- cellId: Unique identifier of the cell. On GSM, this is the Cell ID (CID); CDMA networks use the Base Station ID (BID).
- locationAreaCode: The Location Area Code (LAC) for GSM networks; CDMA networks use Network ID (NID).
- mobileCountryCode: The cell tower's Mobile Country Code (MCC).
- mobileNetworkCode: The cell tower's Mobile Network Code. This is the MNC for GSM, or the System ID (SID) for CDMA.
- age: The number of milliseconds since this cell was primary. If age is 0, the cellId represents a current measurement.
- signalStrength: Radio signal strength measured in dBm.
- timingAdvance: The timing advance value.
This code doesn't especially getting cell towers information.
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) {}
}
And I set permissions like this:
<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"/>
Please help me, thank you.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…