I want to use requestCellInfoUpdate in Android 9

411 Views Asked by At

I'm using requestCellInfoUpdate() callback to get the latest cell info results. It is working fine in Android version Q and above but when I use it in versions below 10, the app crashes. My goal is to continuously get the latest cell info results in all Android versions. Looking forward to your response. It is extremely important for me. Thanks!

telephonyManager.requestCellInfoUpdate(this.getMainExecutor(), new TelephonyManager.CellInfoCallback() {
        @Override
        public void onCellInfo(@NonNull List<CellInfo> cellInfos) {
            Toast.makeText(MainActivity.this, "Helsinki", Toast.LENGTH_SHORT).show();
                cellInfoList.clear();
                for (int i = 0; i < cellInfos.size(); i++) {
                    CellInfo cellInfo = cellInfos.get(i);
                    if (cellInfo.isRegistered())
                        cellInfoList.add(cellInfo);
                }
                bindValues();
        }
    });
1

There are 1 best solutions below

0
On BEST ANSWER

For Android version below Q use telephonyManager.getAllCellInfo() to get cell info.

for (final CellInfo cellInfo : telephonyManager.getAllCellInfo()) {
     if (cellInfo.isRegistered()) {
           //TODO: Do your logic here
     }
}