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.
You can always
getSystemService(Context.TELEPHONY_SERVICE)
.On a device without radio hardware,
getDeviceId()
will returnNULL
. 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 of000000000000000
.In the free version of Genymotion,
getDeviceId()
returns and IMEI of000000000000000
(however I just noticed that their Lollipop preview device returnsNULL
). If you have the paid version, you can set any IMEI using the ID button on the VM skin.