10
Uniquely Identifying Android Devices without special permissions.

Something that you always come across in writing algorithms for devices that you want to lock down is getting a grasp of the actual device it is intended to be on. Sometimes programmers want to lock a registration code not only to a name for registration, but also to a device. This can cut down on “sharing” of serial numbers etc. I was doing some research and looking for device specific information when I stumbled upon a few things. They are right out there in the open, but here they are just in case you have not seen them yet.

In Android.Provider.Settings.System we have some interesting values that could be of use, one specifically is “Android_ID”. From the documentation it is the following;

String ANDROID_ID The Android ID (a unique 64-bit value) as a hex string. “android_id”

Though while this is considered a “unique key”, please keep in mind that if a program has write access to the Settings, which is possible, this could be changed easily. Though it could be a safe assuming that it should not be changed, and upon normal program usage it wouldn’t be changed. Anyway, to retrieve this ID you just use the following snip-it of code;

Also, note that in an emulator this will return “null”, though a real device will return an actual value. The nice thing about this tid-bit of code is that you are not required any special permissions to call it, since it’s essentially a passive call to get information. No write access is (obviously) required.

Tim
4 Comments
  1. It seems that your code is outdated. For some reason the line of code used to get the Android_id is not making any sense if copied into an IDE.

    Janusz

  2. it’s

    Secure.getString(getContentResolver(), Secure.ANDROID_ID);

  3. @Nils

    It is now, if you look at when this article was written – it was using an older SDK, before the call became deprecated and moved to Secure. :)

  4. I’ve had what I thought was the same requirement. Had some problems both actual and possible (some net searches have thrown up some issues) with the elegant code here. So I’ve changed my requirement and am using a somewhat different solution. I’ve put a snippet/sample/hack here:

    http://appdreams.blogspot.com/2010/12/android-and-unique-phone-id.html

Your Name Email Website