1

我正在构建一个应该发送短信的 android 应用程序。发送短信时,我想检查信号强度是否足以发送短信。如果没有,那么应用程序应该构建一个监听器来监听信号强度并在信号足够时发送短信。

我认为我只需要检查是否有任何信号,因为我相信只有非常低的信号就足以发送短信。我应该android.telephony.SignalStrength getGsmSignalStrength()在一开始检查什么是信号强度。如果返回值为 0 那么我应该创建一个监听器LISTEN_SIGNAL_STRENGTHS吗?或者有没有更好的方法?

谢谢转发

4

1 回答 1

1

用这个:

   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.");
                    }
                }
          }

获取所有网络(LTE、GSM、CDMA 和 WCDMA)的信号强度(以 dBm 和 asu 为单位)。然后创建一个 if() 来限制信号电平。前任。:

if (dBmlevel <= x){ print("You can't sent messages with this current signal");}
于 2015-01-08T15:28:34.320 回答