I'm working on a small app that gets information about current and neighboring network base stations cells.
I can get cell_id of my current base station( isRegistered == true ), but for all others I get Int.MAXVALUE
Any solution how to get neighboring cell ids?
I tried another app with Java code but the result is the same. There is no other way to get info about network than telephony manager and I have no idea what to do now.
val tel = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
val infos = tel.allCellInfo
for (i in infos.indices) {
try {
val info = infos[i]
if (info is CellInfoGsm)
//if GSM connection
{
val identityGsm = info.cellIdentity
if(identityGsm.cid != Int.MAX_VALUE && identityGsm.cid != Int.MAX_VALUE)
cellId = identityGsm.cid
val gsm = info.cellSignalStrength
if(gsm.asuLevel != Int.MAX_VALUE)
asuLevel = gsm.asuLevel
if(gsm.dbm != Int.MAX_VALUE)
dbm = gsm.dbm
if(gsm.level != Int.MAX_VALUE)
level = gsm.level
if(gsm.timingAdvance != Int.MAX_VALUE)
timingAdvance = gsm.timingAdvance
technogy = "gsm"
} else if (info is CellInfoLte)
//if LTE connection
{
val identityLte = info.cellIdentity
identityLte.pci
if(identityLte.ci != Int.MAX_VALUE)
cellId = identityLte.ci
val lte = info.cellSignalStrength
if(lte.asuLevel != Int.MAX_VALUE)
asuLevel = lte.asuLevel
if(lte.dbm != Int.MAX_VALUE)
dbm = lte.dbm
if(lte.level != Int.MAX_VALUE)
level = lte.level
if(lte.timingAdvance != Int.MAX_VALUE )
timingAdvance = lte.timingAdvance
//LTE stuff
if(lte.rsrp != Int.MAX_VALUE)
rsrp = lte.rsrp
if(lte.rsrq != Int.MAX_VALUE)
rsrq = lte.rsrq
if(lte.rssnr != Int.MAX_VALUE)
rssnr = lte.rssnr
technogy = "lte"
//call whatever you want from lte / identityLte
} else if (info is CellInfoWcdma)
//if WCDMA connection
{
val identityWcdma = info.cellIdentity
if(identityWcdma.cid != Int.MAX_VALUE)
cellId = identityWcdma.cid
val wcdma = info.cellSignalStrength
if(wcdma.asuLevel != Int.MAX_VALUE)
asuLevel = wcdma.asuLevel
if(wcdma.dbm != Int.MAX_VALUE)
dbm = wcdma.dbm
if(wcdma.level != Int.MAX_VALUE)
level = wcdma.level
technogy = "wcdma"
}
if(cellId != Int.MAX_VALUE){
if (info.isRegistered) { //spI'm connected to this cell
networkCellInfo.CellId = cellId.toString()
}
var neighbor = NeighbourCellInfo()
neighbor.RSRQ = rsrq
neighbor.RSRP = rsrp
neighbor.RSSNR = rssnr
neighbor.AsuLevel = asuLevel
neighbor.Dbm = dbm
neighbor.Level = level
neighbor.CellId = cellId
neighbor.Technology = technogy
neihgbors += neighbor
}
} catch (ex: Exception) {
Log.d(TAG + " cells:", ex.message)
}
}
We get cell identity and strengths values for each cell, we only need to get cell_id.