Cannot detect CellInfo NR on Samsung S20

1.1k views Asked by At

I am trying to detect 5G Nr cell info on Samsung S20 (T-Mobile) using Android API

CellIdentityNr https://developer.android.com/reference/android/telephony/CellIdentityNr.html and

CellSignalStrengthNr https://developer.android.com/reference/android/telephony/CellSignalStrengthNr

Here is my code which detects the cell info:

try {
            if (cellInfo instanceof CellInfoGsm) {
                CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
                logGSMCellInfo(cellInfoGsm, allCellInfoProps);
            } else if (cellInfo instanceof CellInfoLte) {
                CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
                logLTECellInfo(cellInfoLte, allCellInfoProps);
            } else if (cellInfo instanceof CellInfoCdma) {
                CellInfoCdma cellInfoCdma = (CellInfoCdma) cellInfo;
                logCDMACellInfo(cellInfoCdma, allCellInfoProps);
            } else if (cellInfo instanceof CellInfoWcdma) {
                CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;
                logWCDMACellInfo(cellInfoWcdma, allCellInfoProps);
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                if (cellInfo instanceof CellInfoTdscdma) {
                    CellInfoTdscdma cellInfoTdscdma = (CellInfoTdscdma) cellInfo;
                    logTDSCDMACellInfo(cellInfoTdscdma, allCellInfoProps);
                } else if (cellInfo instanceof CellInfoNr) {
                    CellInfoNr cellInfoNr = (CellInfoNr) cellInfo;
                    logNrCellInfo(cellInfoNr, allCellInfoProps);
                }
            }
            collectionOfCellInfo.add(allCellInfoProps);
        } catch (Exception e) {
            Log.e(TAG, "getLatestCellInfoAsCollection: Exception=" + e.getMessage());
            e.printStackTrace();
        }

The problem is that even when the phone is showing 5G in the top bar indicating 5G connection I am getting WCDMA cell info when I should be getting Nr.

From this link, I gathered that the CellInfoNr object is only collected on NR-SA devices, which would explain why I can't get Nr info on other phones. But why am I not getting it on Samsung S20? Detect 5G NR (SA/NSA) in my Android Application

Is there something wrong with the code, or is this problem caused due to available 5G network mode?

Also how to confirm that my S20 is in 'Standalone (5G)' mode?

1

There are 1 answers

2
Ed Kuhner On

Hashim - I can determine if the network is connected with the code below - but I cannot figure out how to get the CellInfoNR to get the 5G signal strength.

Have you figured out how to get teh CellInfoNR to get all of the details on the 5G Connection?

telephonyManager.listen(new CustomPhoneStateListener(c),PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED);

and then this is the class:

public class CustomPhoneStateListener extends PhoneStateListener {

Context context;

CustomPhoneStateListener(Context c) {
    this.context = c;
}

@Override
public void onDisplayInfoChanged(@NonNull TelephonyDisplayInfo telephonyDisplayInfo) {
    if (ActivityCompat.checkSelfPermission(context, android.Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
    } else {
        super.onDisplayInfoChanged(telephonyDisplayInfo);
        if (telephonyDisplayInfo.getOverrideNetworkType() == TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA) {
            //do something
        }
        if (telephonyDisplayInfo.getOverrideNetworkType() == TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE) {
            //do something else
        }
    }

}

}