我正在构建一个应该发送短信的Android应用程序。发送短信时,我想检查信号强度是否足以发送短信。如果没有那么应用程序应该构建一个侦听信号强度的侦听器,并在信号足够时立即发送短信。
我认为我只需要检查是否有任何信号,因为我认为只有非常低的信号足以发送短信。我应该在开始时使用android.telephony.SignalStrength getGsmSignalStrength()
来检查信号强度是多少。如果返回值为0,那么我应该创建一个监听器LISTEN_SIGNAL_STRENGTHS
?还是有更好的方法吗?
先谢谢
答案 0 :(得分: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");}