Currently I wanted to check the strength of the signal before starting to upload the data to server on both android and iOS no matter is wifi or cellular connection.
I came across with this code on android:
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> cellInfos = telephonyManager.getAllCellInfo(); //This will give info of all sims present inside your mobile
if(cellInfos!=null){
for (int i = 0 ; i<cellInfos.size(); i++){
if (cellInfos.get(i).isRegistered()){
if(cellInfos.get(i) instanceof CellInfoWcdma){
CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) telephonyManager.getAllCellInfo().get(0);
CellSignalStrengthWcdma cellSignalStrengthWcdma = cellInfoWcdma.getCellSignalStrength();
strength = String.valueOf(cellSignalStrengthWcdma.getDbm());
}else if(cellInfos.get(i) instanceof CellInfoGsm){
CellInfoGsm cellInfogsm = (CellInfoGsm) telephonyManager.getAllCellInfo().get(0);
CellSignalStrengthGsm cellSignalStrengthGsm = cellInfogsm.getCellSignalStrength();
strength = String.valueOf(cellSignalStrengthGsm.getDbm());
}else if(cellInfos.get(i) instanceof CellInfoLte){
CellInfoLte cellInfoLte = (CellInfoLte) telephonyManager.getAllCellInfo().get(0);
CellSignalStrengthLte cellSignalStrengthLte = cellInfoLte.getCellSignalStrength();
strength = String.valueOf(cellSignalStrengthLte.getDbm());
}
}
}
return strength;
}
Is this only check for the cellular connection not the wifi connection, how to classify into low, medium, and high strength