應用能夠獲取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測驗結果都是這樣,各位覺得問題出在哪里?
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/284468.html
標籤:Android
上一篇:Android WebView集成eCharts,在formatter中添加函式,echarts不顯示
下一篇:關于@NonNull
