16

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?

2
  • 1
    If you register this listener when your app starts then you have the current signal strength. It won't change until you get called by the listener again at which point you can update your internal variable storing the strength.
    – Ryan
    May 13, 2013 at 19:35
  • Like Ryan says...if you keep track of the current signal strength then you will always know what it currently is!
    – Vorsprung
    May 13, 2013 at 19:51

3 Answers 3

29

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.

5
  • 1
    Worked perfectly for me. I just added the if branch for the CellinfoCdma too.
    – Minoru
    Sep 13, 2016 at 16:23
  • You could have edited the answer to add the additional CellInfoCdma
    – Carlos.V
    Nov 6, 2018 at 22:57
  • @Carlos.V That applies to you also, you could have edited the answer. -_-
    – Ananth
    Aug 1, 2019 at 10:30
  • @AnanthRajSingh no, thanks! :), you could also edited it jaja
    – Carlos.V
    Aug 1, 2019 at 15:28
  • 1
    @AnanthRajSingh nice.. you deserve it
    – Carlos.V
    Aug 1, 2019 at 16:56
23

There is getAllCellInfo() method in TelephonyManager added in API 17 that could be good solution. Example of use:

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();
6
  • 1
    Good one but i use lower api, i still voted for the answer thanks. May 15, 2013 at 13:39
  • 11
    Just a heads up: It seems that some devices (looking at you Samsung) don't properly implement getAllCellInfo() and will return null. Nov 19, 2013 at 13:29
  • 4
    You will also need to add this permission code to your manifest... <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> May 13, 2014 at 13:57
  • @ ban-geoengineering coarse location or fine location ? Feb 18, 2021 at 15:11
  • My IDE is telling me I need the ACCESS_FINE_LOCATION permission (which also requires ACCESS_COARSE_LOCATION)
    – kc_dev
    Feb 9, 2022 at 23:43
4

If you are using a SDK version > 28, you can use getSignalStrength() function like so:

telephonyManager.getSignalStrength().getLevel();

Here is a fully implemented function:

TelephonyManager telephonyManager;

...

int getCellularSignalStrength()  {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {

        if(telephonyManager == null)
            telephonyManager = (TelephonyManager) common.appContext.getSystemService(Context.TELEPHONY_SERVICE);

        return telephonyManager.getSignalStrength().getLevel();
    }
    else
    {
        logRecorder.addWarningLog("Cannot read signal lvl on API lvl " + android.os.Build.VERSION.SDK_INT);
        return -1;
    }
}
1
  • For simple use, this answer is much more concise.
    – kc_dev
    Feb 10, 2022 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.