Android : Not Getting Unique Device_id on Samsung Galaxy Tab - android

When I try to get device_id of my Samsung Galaxy Tab GT-P1010, It returns null value. I 'm using device_id for identify unique device in my database.
I am using following code for this:
String device_id;
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
device_id = telephonyManager.getDeviceId();
Here I'm getting string device_id null.. This code is working fine for my all other device, HTC, LG, Google NExxus ICS etc..
Please give me solution for it ASAP.
Thanks,
Jay Patel

If your requirement is only to generate unique identification of device, you can use the below code:
UUID id=UUID.randomUUID();
//store this in shared pref
String device_id=id.toString();
//later fetch it from share pref
UUID Id=UUID.fromString(device_id);
This is the standard way of recognising the device according to RFC4122

getDeviceId() returns the device's IMEI or MEID, which is tied to the device's SIM card. It sounds like your Galaxy Tab is a wi-fi only device, and has no SIM card; that's why it's not giving you a valid device id.
Unfortunately there is no way to get a device id from a wi-fi only device; I'd suggest using ANDROID_ID or some other id if you get a null value for getDeviceId().

Related

Android - unique and constant device ID

I need to register user devices on server with an unique identifier that be a constant value and doesn't change in the future.
I can't find a good solution to get unique id from all devices (with/without simcard).
Secure.ANDROID_ID: Secure.ANDROID_ID is not unique and can be null or change on factory reset.
String m_androidId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
IMEI: IMEI is dependent on the Simcard slot of the device, so it is not possible to get the IMEI for the devices that do not use Simcard.
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String uuid = tManager.getDeviceId();
WLAN MAC Address: If device doesn’t have wifi hardware then it returns null MAC address. and user can change the device mac address.
WifiManager m_wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
String m_wlanMacAdd = m_wm.getConnectionInfo().getMacAddress();
Bluetooth Address string:If device hasn’t bluetooth hardware then it returns null.
BluetoothAdapter m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
String m_bluetoothAdd = m_BluetoothAdapter.getAddress();
Instance id: instance_id will change when user uninstalls and reinstalls app. and it's not a constant value.
Do you have any idea to get a unique id from all Android devices (with/without simcard, Bluetooth, ...) that really be unique, cannot be null and doesn't change after uninstall/reinstall app?
I found that Secure.ANDROID_ID is the best choice. This is a 64-bit quantity that is generated and stored when the device first boots. But it resets on device factory reset.
there are some reports that shows some devices has same Secure.ANDROID_ID on all instances.
we can add extra items (like sim serial, GCM instance id or ...) to the Secure.ANDROID_ID and generate new unique fingerprint.
Mutiple users can be setup on Android device and Secure.ANDROID_ID is different for every user on same Android device. So using Secure.ANDROID_ID means single devices will be registered as a different device for each user setup on the device.
Secure.ANDROID_ID is your only friend. However it has some problems (empty results) on older (<2.3) devices. All other ID's do not work on all type of devices.
Please also read Is there a unique Android device ID?

IMEI number issue: IMEI number is changing using code

I am using a dual Sim phone And sometimes I get different IMEI numbers using the following code:
TelephonyManager manager = (TelephonyManager)
MyApplication.getInstance().getSystemService(Context.TELEPHONY_SERVICE);
String imeiNumber = manager.getDeviceId();
How to resolve this.
As per this question, device manufacturers modify Android to support dual SIMs. However, you can use reflection to get the details of both SIMs.

Is there any way to get unique hardware ID on android devices?

Right now my algorithm based only on IMEI. And here is the problem: some devices doesn't have radio module, so they also doesn't have IMEI
I need unique parameters ( CPU ID, flash ID, MAC etc) to generate ID without using IMEI.
And how to get them with Java. Preferably without Root
Thank you
Use Build.SERIAL to get the unique serial number of an android device. This will return a string value. In emulator this code may return the string "unknown". But try it with a device. It really works... :)
String id=Build.SERIAL;
ANDROID_ID
More specifically, Settings.Secure.ANDROID_ID. This is a 64-bit quantity that is generated and stored when the device first boots. It is reset when the device is wiped.
ANDROID_ID seems a good choice for a unique device identifier. There are downsides: First, it is not 100% reliable on releases of Android prior to 2.2 (“Froyo”). Also, there has been at least one widely-observed bug in a popular handset from a major manufacturer, where every instance has the same ANDROID_ID.
This could help you
You may use android.os.Build.getSerial() instead of android.os.Build.SERIAL
android.os.Build.SERIAL --> This field was deprecated in API level O. Use getSerial() instead.
Source:
https://developer.android.com/reference/android/os/Build.html
You can use the Setting.secure which is inbuilt to get the device id. this device ID is fixed till you reset the factory setting.
Settings.Secure.getString(getContentResolver(),Settings.Secure.ANDROID_ID);
This is the unique Id of your device which is stable till you reset to the factory setting.
below code can help you to get your device id
String ts = Context.TELEPHONY_SERVICE;
TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(ts);
String imsi = mTelephonyMgr.getSubscriberId();
String imei = mTelephonyMgr.getDeviceId();

android imei number for tablet

In my application i have to get unique number of device for that i am using TelephonyManager.
I am able to get imei or device id in android phones but Is is possible for android tablet (Xoom) to get unique number ?
I am using this code to get imei number but i am not able to get in tablet, enter code here
TelephonyManager telephonyManager1 = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
imei = telephonyManager1.getDeviceId();
I think IMEIs on 3G tablets only. Try to use,
ANDROID_ID
More specifically, Settings.Secure.ANDROID_ID. This is a 64-bit quantity that is generated and stored when the device first boots. It is reset when the device is wiped.
ANDROID_ID seems a good choice for a unique device identifier. There are downsides: First, it is not 100% reliable on releases of Android prior to 2.2 (“Froyo”). Also, there has been at least one widely-observed bug in a popular handset from a major manufacturer, where every instance has the same ANDROID_ID.
Look at Here

how to obtain mobile number of own device in android?

I want to retreive mobile number of device programatically. My code is:-
TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String strMobileNumber = telephonyManager.getLine1Number();
and I have set READ_PHONE_STATE permission in AndroidManifest.xml file. This is working on emulator but on actual device with eclair version, it is returning empty string. Is there any other way to get mobile no?
There is no reliable way to "retreive mobile number of device programatically", AFAIK. getLine1Number() reports the number supplied by the SIM card for GSM phones, and the mobile number does not need to be on the SIM card.

Categories

Resources