get SignalStrength without Using PhoneStateListener onSignalStrengthchanged

后端 未结 4 1212
無奈伤痛
無奈伤痛 2020-12-06 15:07

does anyone know how to get the signal strength without having to call the onSignalStrengthChanged. The problem with onSignalStrengthchanged is that is it called when the s

4条回答
  •  清歌不尽
    2020-12-06 15:57

    Based on Andre's answer above, in Kotlin you can use this one-liner (again API 17+):

    fun getRadioSignalLevel(): Int {
      return when (val info = telephonyManager.allCellInfo?.firstOrNull()) {
        is CellInfoLte   -> info.cellSignalStrength.level
        is CellInfoGsm   -> info.cellSignalStrength.level
        is CellInfoCdma  -> info.cellSignalStrength.level
        is CellInfoWcdma -> info.cellSignalStrength.level
        else             -> 0
      }
    }
    

提交回复
热议问题