how to read data inside cellInfo in telephonymanager android

3.4k Views Asked by At

I'm trying to make a program that read usual signal levels and other similar stuff and give it to the reader, I used the getAllCellInfo() while it has some data, I can't figure out a way to extract the data inside to make it easily readable. I tried .toString() method but it gave the same results

List<CellInfo> cell=  tm.getAllCellInfo();

Is there a way to make easily readable? Or is there an easier way to take these data?

I'm looking for RSSI and power related parameters.

2

There are 2 best solutions below

0
On

Here is what I have done:

    protected class SignalStrengthListener extends PhoneStateListener {
        @Override
        public void onSignalStrengthsChanged(android.telephony.SignalStrength signalStrength) {

            tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

            ltestr = signalStrength.toString();
            parts = ltestr.split(" ");

            try {
                cellInfoList = tm.getAllCellInfo();
                for (CellInfo cellInfo : cellInfoList) {

                    if (cellInfo instanceof CellInfoLte) {
                        // cast to CellInfoLte and call all the CellInfoLte methods you need
                        // Gets the LTE PCI: (returns Physical Cell Id 0..503, Integer.MAX_VALUE if unknown)

                       cellPci = ((CellInfoLte) cellInfo).getCellIdentity().getPci();
                    }
                }
            } catch (Exception e) {
                Log.d("SignalStrength", "Exception: " + e.getMessage());
            }

            super.onSignalStrengthsChanged(signalStrength);
        }
}

Then I can print the parts array element that I need. Here I am getting the PCI. Then just for a quick check print it with Log.d("TAG", "PCI is " + cellPci); and watch for it in logcat.

You can check out my app that gets LTE RSRP, RSRQ, PCI, etc. at my github: https://github.com/parksjg/IndoorLTE3a

0
On

you can try this with CellInfoLte , CellInfoGsm to get Dbm , AsuLevel , Level ..etc

 List<CellInfo> cellInfos=tel.getAllCellInfo();


       for (CellInfo varcell:cellInfos){

           if (varcell instanceof CellInfoLte){

                CellInfoLte cellInfoLte=(CellInfoLte)varcell;

               CellSignalStrengthLte cellSignalStrengthLte=(CellSignalStrengthLte)cellInfoLte.getCellSignalStrength();

              int Dbm= cellSignalStrengthLte.getDbm();
              int Asu= cellSignalStrengthLte.getAsuLevel();
               int Level= cellSignalStrengthLte.getLevel();


               int vci=cellInfoLte.getCellIdentity().getCi();