Jutikorn
Jutikorn

Reputation: 848

Is android.os.Build.SERIAL unique?

I would like to use a unique id for android device that works for phone and Tablet. (IMEI doesn't work with no SIM card device and sometime MAC Address return null)

I'm not sure is android.os.Build.SERIAL unique or not.

Does anyone know about this?

Thanks, Regards.

Upvotes: 30

Views: 32712

Answers (6)

san88
san88

Reputation: 1384

You can use Build serial and android ID to make your own unique id.

String serial =    Build.SERIAL;
String android_id =Secure.getString(context.getContentResolver(),
                   Secure.ANDROID_ID);

String myKey=serial +android_id ;

Upvotes: 12

Rahul Giradkar
Rahul Giradkar

Reputation: 1818

I think for unique Id you should used android Id. following is code to get Android Id.

String android_id = Secure.getString(this.getContentResolver(),
            Secure.ANDROID_ID);
Log.d("Android","Android ID : "+android_id);

Upvotes: 3

scottyab
scottyab

Reputation: 24039

Serial was only exposed in API:9. but you can get it in older versions using reflection. However the docs mention "if available" so I guess don't rely on it.

String deviceSerial = (String) Build.class.getField("SERIAL").get(
                    null);

Upvotes: 3

Marcin Orlowski
Marcin Orlowski

Reputation: 75646

If it is there, then it is expected to be unique. But there is no guarantee that this property is set. Also it is API 9. Unfortunately there's no easy way to uniquely identify the device. Some properties like said SERIAL can be present, others like ANDROID_ID as NOT unique, some other like MAC depends on presence of WIFI or its state (if wifi module is off, the you may not be able to read its MAC). Some like IMEI cannot be read even device got phone module. So the best approach is to gather as much data as you can, and try to build something you could most likely consider unique device ID

Upvotes: 3

NikkyD
NikkyD

Reputation: 2284

What about a combination of MAC, IMEI and SERIAL ?

You just have to deal with the fact that they all could be non existant esp. on older phones without SIM.

I just find it odd that MAC would return null. This should not be possible imho, as it makes no sense that a mobile device has no MAC.

There are 2 MAC addresses possible but they can be non accessible in some cases.

Upvotes: 1

Graham Borland
Graham Borland

Reputation: 60701

Yes, but note that it was only added in API level 9, and it may not be present on all devices. To get a unique ID on earlier platforms, you'll need to read something like the MAC address or IMEI.

Generally, try reading all the possible IDs, and use whichever are available. See this article for guidance.

Upvotes: 23

Related Questions