zmyzyc1988 2021-05-18 16:09 采纳率: 0%
浏览 463

Android如何获取5GNR信号强度RSRP

应用能够获取4G的信号强度,却无法获取5G的信号强度,通过修改https://github.com/microg/UnifiedNlp项目实现,
信号监听方法用的phoneStateListener方式

telephonyManager=((TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE));
telephonyManager.listen(phoneStateListener,
        PhoneStateListener.LISTEN_CELL_INFO|PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

捕获onCellInfoChanged实现

if (phoneStateListener == null) {
    Handler mainHandler = new Handler(context.getMainLooper());
    mainHandler.post(() -> {
        phoneStateListener = new PhoneStateListener() {

            @Override
            public void onCellInfoChanged(List<CellInfo> cellInfo) {
                System.out.println(JSON.toJSONString(cellInfo));
                if (cellInfo != null && !cellInfo.isEmpty()) {
                    onCellsChanged(cellInfo);
                } else if (supportsCellInfoChanged) {
                    supportsCellInfoChanged = false;
                    onSignalStrengthsChanged(null);
                }
            }

            @Override
            public void onSignalStrengthsChanged(SignalStrength signalStrength) {
                if (!supportsCellInfoChanged) {
                    doScan();
                }
            }
        };
        registerPhoneStateListener();
    });
} else {
    registerPhoneStateListener();
}

并针对5GNR信号进行处理

else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && info instanceof CellInfoNr){
    CellIdentityNr identity = (CellIdentityNr) ((CellInfoNr) info).getCellIdentity();
    int Mcc=(identity.getMccString() != null) ? Integer.valueOf(identity.getMccString()) : CellInfo.UNAVAILABLE;
    int Mnc=(identity.getMncString() != null) ? Integer.valueOf(identity.getMncString()) : CellInfo.UNAVAILABLE;
//            if ( Mcc== Integer.MAX_VALUE) return null;
    CellSignalStrengthNr strength = (CellSignalStrengthNr) ((CellInfoNr) info).getCellSignalStrength();
    return new Cell(Cell.CellType.NR, Mcc, Mnc,
            identity.getTac(), identity.getNci(), identity.getPci(), strength.getDbm());
}

然而,采集到的信号只有4GLTE的信号强度-76(冒号后面的数),5GNR的信号强度为Integer.MAX,也就是没有赋值


使用的小米10、红米k40pro以及华为p40测试结果都是这样,各位觉得问题出在哪里?

  • 写回答

1条回答 默认 最新

  • weixin_39860304 2022-05-26 15:07
    关注

    问题找到了吗

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法