如何获得当前的细胞信号强度?

我想存储单元格信号的强度,我这样做:

private class GetRssi extends PhoneStateListener { @Override public void onSignalStrengthsChanged(SignalStrength signalStrength) { super.onSignalStrengthsChanged(signalStrength); Variables.signal = signalStrength.getGsmSignalStrength(); } } 

好的,但是只有当它改变时才会运行。 我需要当前的信号强度。

有没有一种方法来要求当前的信号强度?

Solutions Collecting From Web of "如何获得当前的细胞信号强度?"

TelephonyManager中的getAllCellInfo()方法添加到API 17中,这可能是一个很好的解决scheme。 使用示例:

 TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); // for example value of first element CellInfoGsm cellinfogsm = (CellInfoGsm)telephonyManager.getAllCellInfo().get(0); CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength(); cellSignalStrengthGsm.getDbm(); 

CellSignalStrengthGsm()已添加API级别17中添加

CellSignalStrengthGsm()。getDbm()会给你的信号强度为dBm

 TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); List<CellInfo> cellInfos = telephonyManager.getAllCellInfo(); //This will give info of all sims present inside your mobile if(cellInfos!=null){ for (int i = 0 ; i<cellInfos.size(); i++){ if (cellInfos.get(i).isRegistered()){ if(cellInfos.get(i) instanceof CellInfoWcdma){ CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) telephonyManager.getAllCellInfo().get(0); CellSignalStrengthWcdma cellSignalStrengthWcdma = cellInfoWcdma.getCellSignalStrength(); strength = String.valueOf(cellSignalStrengthWcdma.getDbm()); }else if(cellInfos.get(i) instanceof CellInfoGsm){ CellInfoGsm cellInfogsm = (CellInfoGsm) telephonyManager.getAllCellInfo().get(0); CellSignalStrengthGsm cellSignalStrengthGsm = cellInfogsm.getCellSignalStrength(); strength = String.valueOf(cellSignalStrengthGsm.getDbm()); }else if(cellInfos.get(i) instanceof CellInfoLte){ CellInfoLte cellInfoLte = (CellInfoLte) telephonyManager.getAllCellInfo().get(0); CellSignalStrengthLte cellSignalStrengthLte = cellInfoLte.getCellSignalStrength(); strength = String.valueOf(cellSignalStrengthLte.getDbm()); } } } return strength; } 

您可以通过以下url了解更多信息: https : //developer.android.com/reference/android/telephony/CellInfo.html

CellInfoCdma,CellInfoGsm,CellInfoLte,CellInfoWcdma是CellInfo的子类。 其中提供了与您的移动networking相关的所有信息。