I want to get the signal level. I use the following method for this. But I do not know how to reach the phone if it is in plane mode or out of service. Can you help me?
public void signalLevel() {
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> all = tm.getAllCellInfo();
String a = all.get(0).getClass().getName();
if (a.equals("android.telephony.CellInfoLte")) {
CellInfoLte cellInfoLte = (CellInfoLte) all.get(0);
CellSignalStrengthLte cellSignalStrengthLte = cellInfoLte.getCellSignalStrength();
signal = String.valueOf(cellSignalStrengthLte.getDbm() + " dB");
} else if (a.equals("android.telephony.CellInfoWcdma")) {
CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) all.get(0);
CellSignalStrengthWcdma cellSignalStrengthWcdma = cellInfoWcdma.getCellSignalStrength();
signal = String.valueOf(cellSignalStrengthWcdma.getDbm() + " dB");
} else if (a.equals("android.telephony.CellInfoGsm")) {
CellInfoGsm cellInfoGsm = (CellInfoGsm) all.get(0);
CellSignalStrengthGsm cellSignalStrengthGsm = cellInfoGsm.getCellSignalStrength();
signal = String.valueOf(cellSignalStrengthGsm.getDbm() + " dB");
}
}
Thanks for your help.