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:
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.
Network Cell Info Lite (for Android) This highly-rated free Android app uses crowdsourced 4G and 5G tower location data from Mozilla Location Services. Once you open the app, go to the "map" tab. You'll see nearby towers, and the app will draw a blue line to the tower you're connected to.
Network Cell Info Lite is exclusive to Android users but is one of the most highly-rated cell tower locator apps in Google Play. This app shows you cell tower locations based on their database so you can easily track signal strength in a specific area.
Cellular Tower Maps uses Google Maps to display the approximate location of cell phone towers and the coverage of each cell on that tower. The data for the maps is crowd-sourced and comes from users who have downloaded the apps, CellMapper for Windows Mobile, CellMapper for Android and CellMapper for BlackBerry.
I had this problem much more recently and it ended up being the fact that
getNeighboringCellInfo
is deprecated from API 23 up. To get around this use something like the following (it's quite annoying, really):
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With