Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Created July 28, 2020 14:53

Revisions

  1. PatilShreyas created this gist Jul 28, 2020.
    17 changes: 17 additions & 0 deletions CellInfoExtractor.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    fun getCellInfo(info: CellInfoGsm): CellInfo {
    val cellInfo = CellInfo()
    cellInfo.radio = RadioType.GSM

    info.cellIdentity.let {
    val (mcc, mnc) = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
    Pair(it.mccString?.toInt() ?: 0, it.mncString?.toInt() ?: 0)
    } else {
    Pair(it.mcc, it.mnc)
    }
    cellInfo.mcc = mcc
    cellInfo.mnc = mnc
    cellInfo.cells = listOf(Cell(it.lac, it.cid, it.psc))
    }

    return cellInfo
    }