I am having an issue in app that has a function which shows current CellId.
Tested this app on various phones but some of them don't want to show even allCellInfo list, however, the app called Network Cell Info works perfect and shows everything about current CellId.
Only when I turn on GPS process works fine and I can see updates of CIDs.
Here is a piece of code (tested on SDK 29):
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@SuppressLint("MissingPermission")
fun getcids(manager: TelephonyManager): Pair<Int, String> {
val cellInfoList = manager.allCellInfo
if (cellInfoList != null) {
for (networkType in cellInfoList) {
if (networkType is CellInfoLte) {
cid = networkType.cellIdentity.ci
break
}
if (networkType is CellInfoWcdma) {
val num = (networkType as CellInfoWcdma).cellIdentity
cid = num.cid
break
}
if (networkType is CellInfoGsm) {
val num = (networkType as CellInfoGsm).cellIdentity
cid = num.cid
break
}
}
return Pair(cid, cellInfoList.toString())
}
else{
cid = 0
return Pair(cid, "")
}
}
What can be done here to get cell info on every phone?
Update
So far I tried this one. Downgraded SDK to 28 and got methods called getNeighboringCellInfo() and getCellLocation(). Tested getCellLocation() on some emulators with Android 8 and lower (as far as I know already Android 9 needs GPS to be turned on to get cell info). Everything was working fine without GPS until I decided to test it on my phones.
As a result app crash on getCellLocation() because it returns null value. However I also checked Network Cell Info where I saw that information about current connections shows without GPS.