You do not need any permissions to obtain the unique ID of the Android device.

Source: Internet
Author: User

You do not need any permissions to obtain the unique ID of the Android device.

Is there a unique Android device ID?
I have sorted out the answer to this question, including adding another article as a supplement, which can perfectly solve this problem.

Question raised by the author:
Does the Android device have a unique id? If so, how can I obtain this id through java code?

Answer:
I read every answer on stack OverStack, Google's developer blog and Android documentation. I think 'pseudo id' is the best choice.

First, let's take a look at why we don't use other methods: User Email.
  • Users can change their emails (very unreliable)

  • API5 + requires Permissions
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />

  • API14 + requires Permissions
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    (How to get the Android device's primary e-mail address)
User mobile phone number
  • Users can change their mobile phone numbers (very unreliable)

  • Permission required<uses-permission android:name="android.permission.READ_PHONE_STATE" />

IMEI
  • Only Android phones are available. The IMEI number is a string of 15-digit numbers, such as 359881030314356
TelephonyManager TelephonyMgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);String szImei = TelephonyMgr.getDeviceId(); 
  • Permission required<uses-permission android:name="android.permission.READ_PHONE_STATE" />

  • Users usually give you a negative comment because you ask them for this permission, because they think that you are stealing their privacy. Obviously, you are collecting some data.

Android ID
  • This is unreliable, because sometimes it is null. It is clearly stated in the document that if you restore the factory settings, it will change. And if you root the phone, you can change this ID.
String m_szAndroidID = Secure.getString(getContentResolver(), Secure.ANDROID_ID); 
  • It returns a string like 9774d56d682e549c without any permissions.
Wlan mac address
  • This can also get a unique ID number, and the returned value is 00: 11: 22: 33: 44: 55. However, when there is no wifi, we cannot obtain data.
WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);String m_szWLANMAC = wm.getConnectionInfo().getMacAddress();
  • Permission requiredandroid.permission.ACCESS_WIFI_STATE
Bluetooth MAC address
  • Most apps on the market do not use Bluetooth. If your apps do not use Bluetooth at all, but you and your users require the Bluetooth permission, you are suspicious.
BluetoothAdapter m_BluetoothAdapter = null; m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();String m_szBTMAC = m_BluetoothAdapter.getAddress();
  • Permission required<uses-permission android:name="android.permission.BLUETOOTH "/>
The most appropriate method: Pseudo-Unique ID
  • API> = 9: The "Build. SERIAL" attribute ensures that the ID is unique. Android devices with more than API 9 currently share 99.5% of the market
    Remember: You only ignore 0.5% of users technically. You can focus on 99.5% of users.

  • API <9: we can read the ROM version number, vendor name, CPU model, and other hardware information of the device to combine a string of 15-digit numbers, which may be repeated, however, the probability is too small to be ignored. Even if we repeat it, the loss of users is only 0.5% at most.

String m_szDevIDShort = "35" + Build. BOARD. length () % 10 + Build. BRAND. length () % 10 + Build. CPU_ABI.length () % 10 + Build. DEVICE. length () % 10 + Build. DISPLAY. length () % 10 + Build. HOST. length () % 10 + Build. ID. length () % 10 + Build. MANUFACTURER. length () % 10 + Build. MODEL. length () % 10 + Build. PRODUCT. length () % 10 + Build. TAGS. length () % 10 + Build. TYPE. length () % 10 + Build. USER. length () % 10; // 13 digits

"35" and the next 13 digits are 15 characters in total. We can get a serial number like 355715565309247, which is very convenient without any permissions.

// Obtain the unique Psuedo IDpublic static String getUniquePsuedoID () {String serial = null; String m_szDevIDShort = "35" + Build. BOARD. length () % 10 + Build. BRAND. length () % 10 + Build. CPU_ABI.length () % 10 + Build. DEVICE. length () % 10 + Build. DISPLAY. length () % 10 + Build. HOST. length () % 10 + Build. ID. length () % 10 + Build. MANUFACTURER. length () % 10 + Build. MODEL. length () % 10 + Build. PRODUCT. length () % 10 + Build. TAGS. length () % 10 + Build. TYPE. length () % 10 + Build. USER. length () % 10; // 13-bit try {serial = android. OS. build. class. getField ("SERIAL "). get (null ). toString (); // API> = 9 use the serial number return new UUID (m_szdevid=.hashcode (), serial. hashCode ()). toString ();} catch (Exception exception) {// serial requires an initialization serial = "serial "; // any initialization} // return new UUID (m_szdevid).hashcode (), serial. hashCode ()). toString ();

In the end, we will get a string of ID: 201710000-28ee-3eab-ffff-ffffe9374e72.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

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.