问题描述
我希望有人可能有通过 kotlin 上的 android studio 获取手机信号信息的经验。如果没有,请说明为什么我无法收到此信息。
我可以获得很多小区信号信息,例如 RSRP 和 RSRQ,但是每次我尝试获取 RSNR 或 CQI 时,它都不可用。我已经在 android 11 api、google pixel 4a 5G 和 Moto G7 上尝试过这个。都不工作。这是让我获得其他单元格信息的代码:
if (ActivityCompat.checkSelfPermission(
activity,Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
// Todo: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions,and then overriding
// public void onRequestPermissionsResult(int requestCode,String[] permissions,// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return
}
var telephonyManager0 = activity.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
lateinit var infoAllCells : CellInfo
lateinit var infoCell : CellInfo
try{
var infoAllCells = telephonyManager0.allCellInfo
telephonyManager0.requestCellInfoUpdate(activity.mainExecutor,object : TelephonyManager.CellInfoCallback() {
override fun onCellInfo(activeCellInfo: MutableList<CellInfo>) {
for (cellInfo in activeCellInfo) {
var milis = cellInfo.timestampMillis // This value determines the age of the data.
var sec = milis/1000
Log.d( "TAG","cell info timestamp is: " + sec)
}
}
})
infoCell = infoAllCells[0]
val cellInfoLte = infoCell as CellInfoLte
val cellID = cellInfoLte.cellIdentity
val cellSignalLte = cellInfoLte.cellSignalStrength
rsrp = cellSignalLte.rsrp
rsrq = cellSignalLte.rsrq
var RSSnr0 = cellSignalLte.getRSSnr() // only received 2147...etc,the max value of int,which means unavailable.
val cqi0 = cellSignalLte.cqi// only received 2147...etc,which means unavailable.
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)