Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect 5G NR (SA/NSA) in my Android Application

I am trying to detect 5G network. I use the telephony manager to get NETWORK_TYPE. Even if I am in 5G network coverage and my phone shows 5G, I do not get NETWORK_TYPE_NR. The NETWORK_TYPE is always 13 i.e. LTE. The Phones Engineering service mode shows NR related data. Is there any way to detect NR (Standalone or Non-Standalone) mode?

I also need to get the Cell Information for NR data. I use telephonyManager.getAllCellinfo(), but I never get an instance of cellinfonr.

Any help is appreciated. Thanks

like image 812
Akshay Chougule Avatar asked Jun 11 '20 19:06

Akshay Chougule


People also ask

How do I know if my Android is connected to 5G?

To check if your Android phone supports the 5g network, you need to open the 'Settings' app on your phone and further tap the option 'Wi-Fi & Network'. Now, tap on the option 'SIM & Network' and there you will be able to see a list of all technologies under the 'Preferred network type' option.

How can I detect 5G?

The only way to find a 5G signal is to use a 5G cell phone and a coverage map. A tour through the Washington, DC, suburbs, where 5G has been broadly implemented, will give you an idea of what 5G is like right now. You'll find places with strong 5G signals, but you'll also find spots where the only signals are 4G LTE.

What is 5G NR NSA?

5G NSA is a solution for 5G networks where the network is supported by the existing 4G infrastructure. On Android 10, devices can display a 5G icon on the status bar when a device connects to a 5G network.

How do I enable 5G on my Android?

Enable 5G on your phone.Open Settings, and then search for and select Network mode. Tap Network mode, and then tap an option that includes 5G connectivity, or GLOBAL.


1 Answers

I faced the same problem for a few weeks ago. In my case, I want to detect 5G network on Galaxy S20-5G but the getDataNetworkType() always return 13 NETWORK_TYPE_LTE. Following by netmonster-core strategy, and here is the code that I extract from them to solve my problem.

public boolean isNRConnected(TelephonyManager telephonyManager) {
    try {
        Object obj = Class.forName(telephonyManager.getClass().getName())
                .getDeclaredMethod("getServiceState", new Class[0]).invoke(telephonyManager, new Object[0]);
        // try extracting from string
        String serviceState = obj.toString();
        boolean is5gActive = serviceState.contains("nrState=CONNECTED") ||
                serviceState.contains("nsaState=5") ||
                (serviceState.contains("EnDc=true") &&
                        serviceState.contains("5G Allocated=true"));
        if (is5gActive) {
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

Here is full detector class from netmonster-core: (DetectorLteAdvancedNrServiceState.kt)

like image 115
Sophoun Avatar answered Oct 05 '22 22:10

Sophoun