Determine if signal strength is enough to send SMS

1.6k views Asked by At

I am building an android app that should send sms. When sending SMS I want to check if signal strength is enough to send sms. When not then the app should build a listener that listens for signal strength and send sms as soon as signal is enough.

I think that I only need to check if there is any signal because I believe that only a very low signal is enough to send SMS. Should I use android.telephony.SignalStrength getGsmSignalStrength() at begining to check what is the signal strength. If returned value is 0 then I should create a listener LISTEN_SIGNAL_STRENGTHS? Or is there any better way?

Thanks in forward

1

There are 1 answers

6
Matheus Shita On BEST ANSWER

Use this:

   int dBmlevel = 0;
   int asulevel = 0;
   List<CellInfo> cellInfoList = tm.getAllCellInfo();
          //Checking if list values are not null
            if (cellInfoList != null) {
                for (final CellInfo info : cellInfoList) {
                    if (info instanceof CellInfoGsm) {
                        //GSM Network
                        CellSignalStrengthGsm cellSignalStrength = ((CellInfoGsm)info).getCellSignalStrength();
                        dBmlevel = cellSignalStrength.getDbm();
                        asulevel = cellSignalStrength.getAsuLevel();
                    }
                    else if (info instanceof CellInfoCdma) {
                        //CDMA Network
                        CellSignalStrengthCdma cellSignalStrength = ((CellInfoCdma)info).getCellSignalStrength();
                        dBmlevel = cellSignalStrength.getDbm();
                        asulevel = cellSignalStrength.getAsuLevel();
                    }
                    else if (info instanceof CellInfoLte) {
                        //LTE Network
                        CellSignalStrengthLte cellSignalStrength = ((CellInfoLte)info).getCellSignalStrength();
                        dBmlevel = cellSignalStrength.getDbm();
                        asulevel = cellSignalStrength.getAsuLevel();
                    }
                    else if  (info instanceof CellInfoWcdma) {
                        //WCDMA Network
                        CellSignalStrengthWcdma cellSignalStrength = ((CellInfoWcdma)info).getCellSignalStrength();
                        dBmlevel = cellSignalStrength.getDbm();
                        asulevel = cellSignalStrength.getAsuLevel();
                    }
                    else{
                        //Developed as a Cordova plugin, that's why I'm using callbackContext
                        callbackContext.error("Unknown type of cell signal.");
                    }
                }
          }

To get signal strength (in dBm and asu) for all networks (LTE, GSM, CDMA and WCDMA). And then create an if() to limit signal level. Ex.:

if (dBmlevel <= x){ print("You can't sent messages with this current signal");}