Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Device ID Giving null Value [duplicate]

Tags:

android

I am trying to get Unique ID[I.E unique id of a device] by using below code

TelephonyManager tManager;

tManager = (TelephonyManager).getSystemService(Context.TELEPHONY_SERVICE);

String deviceId = tManager.getDeviceId();

Where deviceId Gives me Unique ID for Android Device. I am not testing this on emulator because in emulator i am getting value 000000000000000

Any way i am testing it on real devices,and this works fine for mostly all devices , but in some device i am getting value null

I have tested this on

Samsung Galaxy S3

Samsung Galaxy Tab3

Samsung Galaxy Star

Google Nexus4

Google Nexus5

Google Nexus7

In all the devices listed above it gives me correct out put except one Device and that is Google Nexus7, in this i m getting value null

So, ultimately my goal is to get unique value for each particular device, In case if this code gives me null value than i can try some alternate way

i heard that Device MAC Address is a unique for all devices, But unfortunately it just works on wifi connection.

So is there any other way to get unique value of each particular device?

Thanks Any way

like image 565
Aamirkhan Avatar asked Feb 20 '14 14:02

Aamirkhan


People also ask

Why am I getting invalid device ID or failed to get?

This will show what the signals look like without being affected by the target board hardware. Here is a list of common reasons for getting the " Invalid Device ID " or " Failed to get device ID " error: Bad connection between the programmer and the programming pins on the PIC microcontroller.

What is device unique identifier (DUID)?

Device Unique Identifiers (DUIDs) Because techniques for uniquely identifying devices often become obsolete as technology evolves, Microsoft has developed a device ID format called the device unique ID (DUID) that is extensible and that can incorporate new techniques to identify devices as they become available.

How to get device ID for Android device using telephony manager?

TelephonyManager tManager; tManager = (TelephonyManager).getSystemService (Context.TELEPHONY_SERVICE); String deviceId = tManager.getDeviceId (); Where deviceId Gives me Unique ID for Android Device.

Should I use the Android_ID or the device ID?

You shouldn't really use the ANDROID_ID, you have no real guarantee that it will give you a unique identifier for the device and it is known that some older devices give the value null, or as in Moto's case, the same static value across multiple devices.


1 Answers

You shouldn't really use the ANDROID_ID, you have no real guarantee that it will give you a unique identifier for the device and it is known that some older devices give the value null, or as in Moto's case, the same static value across multiple devices. This value also changes when the phone is reset to the factory default, and is super easy to change on a rooted device.

The correct way is to generate your own UUID via.

String uudid = UUID.randomUUID()

You then save this in your App, for example through a SharedPreference. You can then use Google's Android backup storage to retain this identifier even if the user uninstalls your App.

More information on Backup here: http://developer.android.com/guide/topics/data/backup.html

If you don't take my word for it, you should take Reto Meier's word for it, he is a developer advocate at the Google Android team. This video will explain what I just told you, check out around minute 15, he also specifically instructs developers not to use the ANDROID_ID.

http://www.youtube.com/watch?v=twmuBbC_oB8&list=WL86437554BC3E54B5

like image 168
Ernir Erlingsson Avatar answered Oct 02 '22 15:10

Ernir Erlingsson