[Android] obtain the unique identifier of an Android device | device ID | serial number | UUID

Source: Internet
Author: User

 

How to obtain a sequence number that uniquely identifies each Android device?

There are many answers to this question, but most of them are valid only in some cases.

Based on tests:

  • all devices can return a telephonymanager. getdeviceid ()
  • A telephonymanager. getsimserialnumber ()
  • for all CDMA devices, getsimserialnumber () Returns a null value!
  • All devices with a Google account can return oneAndroid_id
  • All CDMA DevicesAndroid_id AndTelephonymanager. getdeviceid () Returns the same value (as long as a Google account is added at the time of setup)
  • Not tested yet: GSM devices without SIM cards, GSM devices without Google accounts, and devices in flight mode.

So if you want to get the unique serial number of the device,Telephonymanager. getdeviceid () That's enough. However, obviously exposing DeviceID will make some users dissatisfied, so it is best to encrypt these IDs. In fact, the encrypted serial number can still uniquely identify the device, and does not explicitly expose the user's specific device, for example, using string. hashcode (), combined with UUID:

Final telephonymanager TM = (telephonymanager) getbasecontext (). getsystemservice (context. telephony_service); final string tmdevice, tmserial, tmphone, androidid; tmdevice = "" + TM. getdeviceid (); tmserial = "" + TM. getsimserialnumber (); androidid = "" + android. provider. settings. secure. getstring (getcontentresolver (), android. provider. settings. secure. android_id); UUID deviceuuid = new UUID (androidid. hashcode (), (long) tmdevice. hashcode () <32) | tmserial. hashcode (); string uniqueid = deviceuuid. tostring ();

The final DeviceID may be as follows:201710000-54b3-e7c7-0000-000046bffd97

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.