Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current cell signal strength?

I would like to store the cell signal strength, and I do it like this:

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


    }

}

Okay but this only runs if it changes. I need the current signal strength.

Is there a method to just ask for the current signal strength?

like image 777
Adam Varhegyi Avatar asked May 13 '13 19:05

Adam Varhegyi


People also ask

How can I check my cellular signal strength?

For AndroidGo to the Settings app > About phone > Status > SIM status > Signal Strength. You will see numbers expressed in dBm (decibel milliwatts).

How do I refresh my cell phone signal?

Turning your phone's connection off and then back on is the quickest and easiest way to try and fix your signal woes. If you're moving around from one location to another, toggling Airplane mode restarts the Wi-Fi, Bluetooth and cellular network modems, which forces them to find the best signal in the area.

How do I know if my signal is strong?

Cell phone signal strength is measured in decibels (dBm). Signal strengths can range from approximately -30 dBm to -110 dBm. The closer that number is to 0, the stronger the cell signal. In general, anything better than -85 decibels is considered a usable signal.


1 Answers

CellSignalStrengthGsm() is added Added in API level 17

CellSignalStrengthGsm().getDbm() will give you the signal strength as dBm

 private static String getSignalStrength(Context context) throws SecurityException {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String strength = null;
    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) cellInfos.get(i);
                    CellSignalStrengthWcdma cellSignalStrengthWcdma = cellInfoWcdma.getCellSignalStrength();
                    strength = String.valueOf(cellSignalStrengthWcdma.getDbm());
                } else if (cellInfos.get(i) instanceof CellInfoGsm) {
                    CellInfoGsm cellInfogsm = (CellInfoGsm) cellInfos.get(i);
                    CellSignalStrengthGsm cellSignalStrengthGsm = cellInfogsm.getCellSignalStrength();
                    strength = String.valueOf(cellSignalStrengthGsm.getDbm());
                } else if (cellInfos.get(i) instanceof CellInfoLte) {
                    CellInfoLte cellInfoLte = (CellInfoLte) cellInfos.get(i);
                    CellSignalStrengthLte cellSignalStrengthLte = cellInfoLte.getCellSignalStrength();
                    strength = String.valueOf(cellSignalStrengthLte.getDbm());
                } else if (cellInfos.get(i) instanceof CellInfoCdma) {
                    CellInfoCdma cellInfoCdma = (CellInfoCdma) cellInfos.get(i);
                    CellSignalStrengthCdma cellSignalStrengthCdma = cellInfoCdma.getCellSignalStrength();
                    strength = String.valueOf(cellSignalStrengthCdma.getDbm());
                }
            }
        }
    }
    return strength;
}

Please note that above code will return strength of the last cell in the list.

You can learn more from: https://developer.android.com/reference/android/telephony/CellInfo.html

CellInfoCdma, CellInfoGsm, CellInfoLte, CellInfoWcdma are the subclasses of CellInfo. Which gives all information related to your mobile network.

like image 95
Rahul Lad Avatar answered Sep 22 '22 10:09

Rahul Lad