用这个:
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");}