Android cell tower values always 2147483647

Viewed 955

I am trying to do something along the lines of signal strength triangulation using cell towers, on android. I'm using android studio and java. I've found useful csv with cell tower latitude and longitude, and written some fairly trivial code to parse it, all I need now is the cell towers' mcc, mnc, lac and cell id, so I can search the csv and find the lat and long. I'm using the telephonyManager class and .getAllCellInfo(), like so:

    tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    InputStream inputStream = getResources().openRawResource(R.raw.cells);
    CsvFile csvFile = new CsvFile(inputStream);
    List<String[]> res = csvFile.read();

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

    for (CellInfo ci : cellsTemp) {

        if (ci instanceof CellInfoLte) {
            Log.d("Cells: ", ((CellInfoLte) ci).getCellIdentity().toString());
            this.cellsLte.add((CellInfoLte) ci);
            this.towers.add(new cellTower((CellInfoLte) ci, res));
        }
    }

However, when I log the cellIdentity of those cells, I get this:

CellIdentityLte:{ mCi=2147483647 mPci=313 mTac=2147483647 mEarfcn=1300 mBandwidth=2147483647 mMcc=null mMnc=null mAlphaLong= mAlphaShort=}

As you can see, the mcc and mnc are null, and the the cell id and location code are 2147483647, or Integer.MAX_VALUE, which as I understand it, is used when they are for whatever reason unavailable.

I have the ACCESS_FINE_LOCATION and READ_PHONE_STATE runtime permissions, and I've added them to the manifest file as well. I've also tried just logging the objects directly from tel.getAllCellInfo(), same exact result.

This is the declaration for tel and towers:

public class MainActivity extends AppCompatActivity {

    protected RequestQueue requestQueue;
    protected TelephonyManager tel;
    protected List<CellInfoLte> cellsLte = new ArrayList<CellInfoLte>();
    protected List<cellTower> towers = new ArrayList<cellTower>();

And cellTower is just a sort of wrapper class that contains some information I'm going to need to calculate distance later. It also contains the cellInfo of the tower.

I am also aware that there are apis that can do this whole thing automatically, but I need to do this myself, as a sort of a proof of concept.

I'm running this on a LGE LG-H870, but I've also tried it on a Xiaomi Redmi 8, and had the same issue.

I am an (almost)complete beginner with android studio, but I think I have a perfectly decent understanding of java. Is there any way at all to get around this? Any help would be greatly appreciated.

0 Answers
Related