我需要从CellSignalStrength.getLevel()得到信号电平
我是从CellInfoGsm拿来的
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
CellInfo allCellInfo = (CellInfo) telephonyManager.getAllCellInfo().get(0);
CellSignalStrength cellSignalStrength = ((CellInfoGsm) allCellInfo).getCellSignalStrength();
int level = cellSignalStrength.getLevel();但是在某些设备上,我从telephonyManager.getAllCellInfo()中获得null,所以android文档说我使用telephonyManager.getNeighboringCellInfo()。
有没有任何方法从CellSignalStrength或“用户友好”信号级别从NeighboringCellInfo获得?
发布于 2014-09-25 09:28:58
我通过从getLevel()重写CellInfoGsm函数来解决它--我想我是这样做的。
我调用NeighboringCellInfo.getRssi(),然后将其转换为级别,就像CellInfoGsm.getLevel()做的那样
for(NeighboringCellInfo nci:telephonyManager
.getNeighboringCellInfo()){
if(neighborCellInfo == null) {
neighborCellInfo = nci;
} else if(nci.getRssi() > neighborCellInfo.getRssi()) {
neighborCellInfo = nci;
}
}
int level;
int GSM_SIGNAL_STRENGTH_GREAT = 12;
int GSM_SIGNAL_STRENGTH_GOOD = 8;
int GSM_SIGNAL_STRENGTH_MODERATE = 8;
// ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
// asu = 0 (-113dB or less) is very weak
// signal, its better to show 0 bars to the user in such cases.
// asu = 99 is a special case, where the signal strength is unknown.
int asu = neighborCellInfo.getRssi();
if (asu <= 2 || asu == 99) level = 0;
else if (asu >= GSM_SIGNAL_STRENGTH_GREAT) level = 4;
else if (asu >= GSM_SIGNAL_STRENGTH_GOOD) level = 3;
else if (asu >= GSM_SIGNAL_STRENGTH_MODERATE) level = 2;
else level = 1;https://stackoverflow.com/questions/26014068
复制相似问题