Chos
Chos

Reputation: 111

How to detect if the NR network is the NSA or SA type(Using the android API)

I know the 5G API has been added in Android Q, I'd like to know if we can detect the network is NSA network or SA network. Appreciated for the information from anybody.

Upvotes: 1

Views: 2000

Answers (2)

Ed Kuhner
Ed Kuhner

Reputation: 428

I do this with the following 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) {
            Log.w(TAG,"5G_NSA");
        }
        if (telephonyDisplayInfo.getOverrideNetworkType() == TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE) {
            Log.w(TAG, "5G_NSA_MMWAVE");
        }
    }

}

}

and then call that class with this:

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

Upvotes: 2

Chos
Chos

Reputation: 111

According to the google document, I'd like to judge the current network is NSA or SA. But I found cellConnectionStatus always is 0... I am using the Galaxy 10s 5G and LG v50 5G devices.

val hasPrimaryLteCell = telephonyManager.allCellInfo
        .filterIsInstance(CellInfoLte::class.java)
        .any {
            it.cellConnectionStatus == CellInfo.CONNECTION_PRIMARY_SERVING
        }

val hasSecondaryNrCell = telephonyManager.allCellInfo
        .filterIsInstance(CellInfoNr::class.java)
        .any {
            it.cellConnectionStatus == CellInfo.CONNECTION_SECONDARY_SERVING
        }

val isIn5GNonStandaloneMode = hasPrimaryLteCell && hasSecondaryNrCell

Upvotes: 1

Related Questions