Raj
Raj

Reputation: 3462

getting cellular network status via ADB shell

Is it possible to check via ADB if the phone is connected to a cellular network?

I had a look at ConnectivityManager, but it is for android application development.

Upvotes: 6

Views: 30833

Answers (3)

mdh-labs
mdh-labs

Reputation: 21

A little late to add to this post. I came to this post looking for the same result and after a while I needed to know the wifi status too. And with little more investigation ...

# dumpsys wifi | grep curState                                
curState=ApStaDisabledState
curState=NotConnectedState
curState=InitialState
curState=UninitializedState
curState=InitialState

This will give you the actual status, whether it is connected to an AccessPoint or it is still trying to connect, or if it is disabled or ...

Note: If you are planning to use the result for time critical services, you may look for other ways as waiting for a response could take a while sometimes (>5s).

Upvotes: 1

escargot agile
escargot agile

Reputation: 22379

To add to Siri's answer, here are the values of mServiceState:

http://developer.android.com/reference/android/telephony/ServiceState.html

public static final int STATE_EMERGENCY_ONLY

Added in API level 1 The phone is registered and locked. Only emergency numbers are allowed.

Constant Value: 2 (0x00000002)

public static final int STATE_IN_SERVICE

Added in API level 1 Normal operation condition, the phone is registered with an operator either in home network or in roaming.

Constant Value: 0 (0x00000000)

public static final int STATE_OUT_OF_SERVICE

Added in API level 1 Phone is not registered with any operator, the phone can be currently searching a new operator to register to, or not searching to registration at all, or registration is denied, or radio signal is not available.

Constant Value: 1 (0x00000001)

public static final int STATE_POWER_OFF

Added in API level 1 Radio of telephony is explicitly powered off.

Constant Value: 3 (0x00000003)

And here are the values of mDataConnectionState:

http://grepcode.com/file/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0_r2-robolectric-0/android/telephony/TelephonyManager.java#TelephonyManager.0DATA_UNKNOWN

Data connection state: Unknown. Used before we know the state.

public static final int DATA_UNKNOWN        = -1;

Data connection state: Disconnected. IP traffic not available.

public static final int DATA_DISCONNECTED   = 0;

Data connection state: Currently setting up a data connection.

public static final int DATA_CONNECTING     = 1;

Data connection state: Connected. IP traffic should be available.

public static final int DATA_CONNECTED      = 2;

Data connection state: Suspended. The connection is up, but IP traffic is temporarily unavailable. For example, in a 2G network, data activity may be suspended when a voice call arrives.

public static final int DATA_SUSPENDED      = 3;

Upvotes: 8

Sirius
Sirius

Reputation: 313

Certainly using the command from shell :

dumpsys telephony.registry

or directly from adb :

adb shell dumpsys telephony.registry

The values of mServiceState or mDataConnectionState will help you. I tried in Plane mode mServiceState=3 / mDataConnectionState=0 and connected to the cellular network : mServiceState=0 / mDataConnectionState=2

PS: I'm using an Android 4.4 phone.

Upvotes: 11

Related Questions