Skip to content Skip to sidebar Skip to footer

Parse Getallcellinfo Values From Telephony Manager

i'm using the following function to get Allcellinfo of an device network and im getting the values as an string now i need to parse it in order to get the CellSignalStrengthLte dat

Solution 1:

I also noticed that CellinfoLTE and CellIdentityLTE is not so great at the moment, so I just wrote my own parsing class. Only tested this a few times, and didn't have problems, but more testing should display if additional future tweaking will be necessary.

Here's the class:

publicclassLTEStruct
{
publicstaticfinalintUNKNOWN= Integer.MAX_VALUE;   //Default value for unknown fieldspublicboolean isRegistered;
publiclong timeStamp;
publicint MCC;
publicint MNC;
publicint CID;
publicint PCI;
publicint TAC;

publicint SS;
publicint RSRP;
publicint RSRQ;
publicint RSSNR;
publicint CQI;
publicint tAdvance;

Context mContext;

//Public constructorpublicLTEStruct(Context context)
{
    mContext = context; //not used at the moment but possibly for future function
}

publicvoidparse(String inTest)
{
    //get isRegisteredintindex= inTest.indexOf("mRegistered=") + ("mRegistered=").length();
    if(inTest.substring(index,index + 3).contains("YES"))
        isRegistered = true;
    elseisRegistered=false;

    //getTimestamp
    timeStamp = getValue(inTest,"mTimeStamp=", "ns");

    //get Cell Identity paramters
    MCC = (int) getValue(inTest,"mMcc=", " ");      //get Mcc
    MNC = (int) getValue(inTest,"mMnc=", " ");      //get MNC
    CID = (int) getValue(inTest,"mCi=", " ");       //get CID
    PCI = (int) getValue(inTest,"mPci="," ");       //get PCI
    TAC = (int) getValue(inTest,"mTac=","}");       //get TAC//get RF related parameters
    SS = (int) getValue(inTest," ss="," ");         //get SS
    RSRP = (int)getValue(inTest,"rsrp=", " ");      //get RSRP
    RSRQ = (int)getValue(inTest,"rsrq=", " ");      //get RSRQ
    RSSNR = (int)getValue(inTest,"rssnr=", " ");    //get RSSNR
    CQI = (int)getValue(inTest," cqi=", " ");       //get CQI
    tAdvance = (int)getValue(inTest," ta=", "}");   //get timing advance
}

//internal function to help with parsing of raw LTE stringsprivatelonggetValue(String fullS, String startS, String stopS)
{
    intindex= fullS.indexOf(startS) + (startS).length();
    intendIndex= fullS.indexOf(stopS,index);

    return Long.parseLong(fullS.substring(index,endIndex).trim());
}

}

So if I implement this very basically with the input LTE string:

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

    //get cell infoTelephonyManager 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 CellInfoLte) {
                LTEStruct lte = new LTEStruct(this);
                lte.parse(info.toString());

                //write out parsed results for what it's worthLog.i("LTE parseOutput", "tAdvance: "+ lte.tAdvance +"\r\nCQI: "+ lte.CQI+"\r\nRSSNR: "+ lte.RSSNR+"\r\nRSRP: "+ lte.RSRP+"\r\nSS: "+ lte.SS+"\r\nCID: "+ lte.CID+"\r\nTimestamp: "+ lte.timeStamp +"\r\nTAC: "+ lte.TAC+"\r\nPCI: "+ lte.PCI+"\r\nMNC: "+ lte.MNC+"\r\nMCC: "+ lte.MCC+"\r\nRegistered: "+ lte.isRegistered);
            } elseLog.i("LTE testing", "not LTE cell info measured");

        } catch (Exception ex) {
            Log.i("neighboring error: ", ex.getMessage());
        }

    }

Hope it helps ;)

Post a Comment for "Parse Getallcellinfo Values From Telephony Manager"