1

this is the phone state listener i'm using to detect the changes

public PhoneStateListener mPhoneStateListener = new PhoneStateListener() {


        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            Log.d("SIGNAL ", "  " + signalStrength.toString());
            TelephonyManager tm = (TelephonyManager) mContext.getSystemService(mContext.TELEPHONY_SERVICE);
            List<CellInfo> cellInfos = tm.getAllCellInfo();
            for (int i=0 ;i<cellInfos.size() ;i++)
            {
                Log.d("test ",cellInfos.get(0).toString() );
            }
        }
    };

The problem is currently i'm getting all cell information as below:

result - > logs CellInfoLte:{mRegistered=YES mTimeStampType=oem_ril mTimeStamp=192908703241551ns CellIdentityLte:{ mMcc=405 mMnc=869 mCi=2971664 mPci=123 mTac=56} CellSignalStrengthLte: ss=27 rsrp=-90 rsrq=-10 rssnr=2147483647 cqi=2147483647 ta=2147483647}

How can i parse this to get CellInfoLte, CellIdentityLte and CellSignalStrengthLte from the above result

Saeed
  • 3,294
  • 5
  • 35
  • 52
RAM
  • 119
  • 1
  • 14

2 Answers2

1

if you're still struggling with the problem, this is the method I'm using:

//permission check
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
        ActivityCompat.requestPermissions((Activity)this,new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},1);

    String list = "";  //I'm just adding everything to a string to display, but you can do whatever

    //get cell info
    TelephonyManager tel = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
    List<CellInfo> infos = tel.getAllCellInfo();
    for (int i = 0; i<infos.size(); ++i) 
        {
            try {
                CellInfo info = infos.get(i);
                if (info instanceof CellInfoGsm) //if GSM connection
                {
                    list += "Site_"+i + "\r\n";
                    list += "Registered: " + info.isRegistered() + "\r\n";
                    CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();
                    CellIdentityGsm identityGsm = ((CellInfoGsm) info).getCellIdentity();
                    list += "cellID: "+ identityGsm.getCid() + "\r\n";
                    list += "dBm: " + gsm.getDbm() + "\r\n\r\n";
                    //call whatever you want from gsm / identitydGsm
                }
                else if (info instanceof CellInfoLte)  //if LTE connection
                {
                    list += "Site_"+i + "\r\n";
                    list += "Registered: " + info.isRegistered() + "\r\n";
                    CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();
                    CellIdentityLte identityLte = ((CellInfoLte) info).getCellIdentity();
                    //call whatever you want from lte / identityLte
                }
                else if (info instanceof CellInfoWcdma)  //if wcdma connection
                {
                    CellSignalStrengthWcdma wcdmaS = ((CellInfoWcdma) info).getCellSignalStrength();
                    CellIdentityWcdma wcdmaid = ((CellInfoWcdma)info).getCellIdentity();
                    list += "Site_"+i + "\r\n";
                    list += "Registered: " + info.isRegistered() + "\r\n";
                    //call whatever you want from wcdmaS / wcdmaid

                }

            } catch (Exception ex) {
                Log.i("neighboring error 2: " ,ex.getMessage());
            }
        }
    Log.i("Info display", list);  //display everything.

And while we're busy, just a heads up, the LTE parsing is all screwy (you will see if you do getCi(), getTac() etc. ), so I wrote my own parsing class, and posted my answer here.

Hede of warning though, when you start to see that your neighboring cell info is totally wrong... (the problem that I'm currently at), this dilemma is also posted here. Good luck, and let me know if this part is not a issue for you

Paul
  • 756
  • 1
  • 8
  • 22
  • Hi Paul, how can I get `CellInfoTdscdma`, as I have to get informarion of all type of cells. – R G Nov 29 '18 at 10:01
  • Vote me up and I'll tell you... Haha, no sorry RG, I don't have the foggiest idea. I crash coursed through this and went on as soon as stuff "worked" for my purpose. Since then I haven't done Android dev. again, nevermind Sig str. measurements via the SDK. – Paul Nov 30 '18 at 12:09
  • Quickly tried to think about it... [CellInfoTdscdma](https://developer.android.com/reference/android/telephony/CellIdentityTdscdma?hl=id&refresh=1) extends cellIdentity base class, while something like [CellInfoCdma](https://developer.android.com/reference/android/telephony/CellInfoCdma) extends CellInfo base class. So likewise, I imagine you have List myList = **//get Cell Identity function**, and extracting CellInfoTdscdma from that. So whatever function is used to get CellIdentity data? – Paul Nov 30 '18 at 12:21
  • There is no `CellInfoTdscdma` class in android developer site. It displays only `CellIdentityTdscdma` class. I am not able to get values of identity class, because in order to get `Identity` class properties value, we must create its `CellInfo` class object. – R G Dec 03 '18 at 12:14
  • It looked relatively straight forward to implement [CellIdentityTdscdma](https://developer.android.com/reference/android/telephony/CellIdentityTdscdma?hl=id&refresh=1) from a [CellIdentity](https://developer.android.com/reference/android/telephony/CellIdentity?hl=id&refresh=1) base class, but apart from that my input is pretty useless until I would be able to experiment with myself... sorry. This was a quick proof of concept for me, so can't really remember all that much – Paul Dec 05 '18 at 08:04
0

Try this (according to cocorico):

String ssignal = signalStrength.toString();
String[] parts = ssignal.split(" ");

Where signalStrength.toString() comes from signalStrength.

The parts[] array will then contain these elements:

part[0] = "Signalstrength:"  _ignore this, it's just the title_
parts[1] = GsmSignalStrength
parts[2] = GsmBitErrorRate
parts[3] = CdmaDbm
parts[4] = CdmaEcio
parts[5] = EvdoDbm
parts[6] = EvdoEcio
parts[7] = EvdoSnr
parts[8] = LteSignalStrength
parts[9] = LteRsrp
parts[10] = LteRsrq
parts[11] = LteRssnr
parts[12] = LteCqi
parts[13] = gsm|lte|cdma
parts[14] = _not really sure what this number is_

So, LTEdBm is :

TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
int dbm = 0;

if ( tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_LTE){
    // For Lte SignalStrength: dbm = ASU - 140.
    dbm = Integer.parseInt(parts[8])-140;
} else {
    // For GSM Signal Strength: dbm =  (2*ASU)-113.
    if (signalStrength.getGsmSignalStrength() != 99) {
        int intdbm = -113 + 2
                        * signalStrength.getGsmSignalStrength();
        dbm = Integer.toString(intdbm);
    }
}
Lil Bro
  • 236
  • 1
  • 7
  • Thank you but this will only give me details regarding the serving cells not neighbor cells, i need to get values of neighbor cells – RAM Nov 01 '17 at 17:44
  • This should work: `String s = "5476 substring=257 string"; // your string String[] split = s.split("substring="); // substring // String firstSubString = split[0]; // 1st part "5476 " String secondSubString = split[1]; // 2nd part "257 string"" String finals=secondSubString.substring(0,3); // Then we get "257"` - the first 3 digits. Change `substring=` to `mMcc=` for example. – Lil Bro Nov 02 '17 at 09:48