2

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

LittleFunny
  • 8,155
  • 15
  • 87
  • 198
  • 1
    Not possible on iOS, that is not exposed by the OS. For Wifi on Android, there are a bunch of Q/As. Also the WifiManager provides a `CalculateSignalLevel` based upon the number of units you wish to break it into (3 in your case). : https://stackoverflow.com/questions/13932724/getting-wifi-signal-strength-in-android – SushiHangover Jun 28 '18 at 03:01
  • Not possible on iOS. Do you mean iOS not even allow to get something like low, medium etc. – LittleFunny Jun 28 '18 at 03:07
  • There are a bunch of private APIs on iOS, but nothing public that is allowed by Apple. I've seen a number of apps that basically perform file transfers to measure latency/throughput speed and calculate a ***pseudo*** signal strength from that... – SushiHangover Jun 28 '18 at 03:17
  • iOS is so strict.. I thought I find a solution but limited by the apple – LittleFunny Jun 28 '18 at 03:18
  • You can search SO (and the internet), people have been asking for the same thing since the release of iOS and either private APIs or jailbreaking is required to obtain system level diagnostic signals. There are a few projects on Github that provide field diagnostic signal levels (at least on older iOS versions) but again these are using private APIs and are not allowed by Apple. – SushiHangover Jun 28 '18 at 03:24
  • Not allow for apple that is the big problem but thank for the time to reply... – LittleFunny Jun 28 '18 at 03:26
  • Initially I want to check by signal strength before sending data to server, if signal strength not strong enough I can store it first. Do you think there is any other way to work around on iOS. – LittleFunny Jun 28 '18 at 04:55
  • You can test for reachability (i.e. can you ping your server), test for latency (what is the round-trip of time of a ping or an ping-style Rest/API on your server), but why not cache/store the data, test for reachability (a simple ping) and if reachable, try to send it, and it successful delete the cached data, otherwise try it at a later time. – SushiHangover Jun 28 '18 at 05:02
  • Good idea I never thought of that – LittleFunny Jun 28 '18 at 21:29

0 Answers0