Do I need a data connection in order to get TELEPHONY_SERVICE?

191 views Asked by At

I am getting the device ID using the TelepphonyManager and Context.TELEPHONY_SERVICE

    TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String uid = tManager.getDeviceId();

Do I need an available 3G/4G/LTE data connection to get the TELEPHONY_SERVICE? Or will this return null if there is no signal?

EDIT:

Does turning off Mobile Data setting in the device system settings completely turn off the data connection as if there was no data connection at all? Because then this would be easy to test.

2

There are 2 answers

0
Paul Ratazzi On BEST ANSWER

You can always getSystemService(Context.TELEPHONY_SERVICE).

On a device without radio hardware, getDeviceId() will return NULL. On a device with a cellular radio, you will get the IMEI/MEID/ESN even if if you disable it (i.e., airplane mode, no SIM, etc.).

In an Android Virtual Device (AVD, a/k/a emulator), getDeviceId() returns an IMEI of 000000000000000.

In the free version of Genymotion, getDeviceId() returns and IMEI of 000000000000000 (however I just noticed that their Lollipop preview device returns NULL). If you have the paid version, you can set any IMEI using the ID button on the VM skin.

0
Mike On

I wasn't able to find something regarding your issue in the android documentation. See here: http://developer.android.com/reference/android/content/Context.html#TELEPHONY_SERVICE

I think the simplest way is to put it on your phone turn off the data connection, start your app and look if it throws a NPE. Hope it helps