/**
* 获取移动信号强度
*/
@SuppressLint("MissingPermission", "NewApi")
private fun getMobileNetworkSignal(context: Context): Int? {
var lastSignal: Int?
if (!hasSimCard(context)) {
logger.debug { "未识别到SIM" }
return null
}
logger.debug { "识别到SIM" }
logger.debug { "正在检测移动信号......." }
val mTelephonyManager = context.getSystemService(TELEPHONY_SERVICE) as TelephonyManager
mTelephonyManager.signalStrength?.let {
it.cellSignalStrengths.map { cell ->
if (cell.toString().contains("CellSignalStrengthLte")) {
lastSignal = cell.dbm
logger.debug { "4G信号强度:$lastSignal dBm" }
return lastSignal
}
}
} ?: logger.debug { "获取4G信号强度出错" }
return null
}
Android 获取4g信号强度
最新推荐文章于 2022-09-17 16:42:57 发布