无法获取相邻的单元格ID(Android)

时间:2019-06-10 07:25:35

标签: android kotlin network-programming cellid

我正在开发一个小型应用程序,该应用程序可获取有关当前和相邻网络基站小区的信息。

我可以获得当前基站(isRegistered == true的cell_id,但是对于其他所有基站,我都可以获得Int.MAXVALUE

任何解决方案如何获取相邻小区ID?

我尝试了另一个使用Java代码的应用程序,但结果是相同的。 除了电话管理器,没有其他方法可以获取有关网络的信息,而且我不知道该怎么办。

        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)
            }

        }

我们获得每个单元格的单元格标识和强度值,我们只需要获取cell_id

0 个答案:

没有答案