Android: Get CellID and RSS for Base Station and Neigboring Cells

I am trying to get the following data:

  • Base Station: CellID and RSS (recognition, which is the base station)
  • For all neighbor stations: CellID and RSS

There are various APIs, and it looks like I will have to use different telephonyManager and PhoneStateListener APIs. I am a little confused since I think this should be available in one interface. Also, I think it should be possible to poll the CellID of the current base station instead of listening to State Changes to determine int, since neighbor-cell stations can also be polled from telephonyManager.

Can you tell me how can I get the data above?

+6
source share
1 answer

New skool-way: API 17 is much nicer and cleaner, but still too new.

List<CellInfo> cellInfos = (List<CellInfo>) this.telephonyManager.getAllCellInfo(); for(CellInfo cellInfo : cellInfos) { CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo; CellIdentityGsm cellIdentity = cellInfoGsm.getCellIdentity(); CellSignalStrengthGsm cellSignalStrengthGsm = cellInfoGsm.getCellSignalStrength(); Log.d("cell", "registered: "+cellInfoGsm.isRegistered()); Log.d("cell", cellIdentity.toString()); Log.d("cell", cellSignalStrengthGsm.toString()); } 

The old API does not provide a very satisfactory solution. But here is the old way:

 this.telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); this.phoneStateListener = setupPhoneStateListener(); this.telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION); this.telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE); this.telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); // This part is used to listen for properties of the neighboring cells List<NeighboringCellInfo> neighboringCellInfos = this.telephonyManager.getNeighboringCellInfo(); for(NeighboringCellInfo neighboringCellInfo : neighboringCellInfos) { neighboringCellInfo.getCid(); neighboringCellInfo.getLac(); neighboringCellInfo.getPsc(); neighboringCellInfo.getNetworkType(); neighboringCellInfo.getRssi(); Log.d("cellp",neighboringCellInfo.toString()); } public PhoneStateListener setupPhoneStateListener() { return new PhoneStateListener() { /** Callback invoked when device cell location changes. */ @SuppressLint("NewApi") public void onCellLocationChanged(CellLocation location) { GsmCellLocation gsmCellLocation = (GsmCellLocation) location; gsmCellLocation.getCid(); gsmCellLocation.getLac(); gsmCellLocation.getPsc(); Log.d("cellp", "registered: "+gsmCellLocation.toString()); } /** invoked when data connection state changes (only way to get the network type) */ public void onDataConnectionStateChanged(int state, int networkType) { Log.d("cellp", "registered: "+networkType); } /** Callback invoked when network signal strengths changes. */ public void onSignalStrengthsChanged(SignalStrength signalStrength) { Log.d("cellp", "registered: "+signalStrength.getGsmSignalStrength()); } }; } 
  • Remember to set all the necessary permissions. The problem with this solution is that I do not get any information about the neighboring cells, although I install:

    uses-permission android: name = "android.permission.ACCESS_COARSE_UPDATES"

(note that I am using a Samsung phone, and this is a known issue that Samsung phones do not support the list of neighboring cells)

+6
source

All Articles