This question comes from is there a unique Android device ID?
I've sorted out the answer to this question, including adding another article as a complement to the problem.
Questions raised by the author:
Does the Android device have a unique ID? If so, how do I get this ID from Java code?
Answer:
I read every answer on Stack overstack, Google developer blogs and Android docs, and I think ' Pseudo ID ' is the best option.
First, let's see why we don't use other methods: User Email
User phone number
Imei
- Only Android phone, IMEI number is a string of 15 digits, such as 359881030314356
Require permissions<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Usually users give you a bad rating because you're asking them to, because they think you're stealing their privacy, and obviously you're collecting some data.
Android ID
- This is not reliable, because sometimes it is null, the document clearly stated that if you restore the factory settings, then he will change. And if you root the phone, you can also change the ID
- It returns a bunch of things like 9774d56d682e549c, but it doesn't need any permissions.
WLAN MAC Address
- This can also get a unique ID number, which is returned by 00:11:22:33:44:55. But when there is no wifi, we can't get the data.
WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);String m_szWLANMAC = wm.getConnectionInfo().getMacAddress();
- Require permissions
android.permission.ACCESS_WIFI_STATE
Bluetooth MAC Address
- Most of the applications on the market do not use Bluetooth, if your app does not have Bluetooth, and you and the user want Bluetooth rights, then you are suspicious.
null; m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();String m_szBTMAC = m_BluetoothAdapter.getAddress();
- Require permissions
<uses-permission android:name="android.permission.BLUETOOTH "/>
The most appropriate approach: Pseudo-unique ID
API >=9: Use the "build.serial" attribute to ensure that the ID is unique. API 9 or more Android devices now have a market share of 99.5%
Remember : You only technically ignore 0.5% of users, you can focus on 99.5% of users
API < 9: We can read the device's ROM version number, manufacturer name, CPU model and other hardware information to assemble a string of 15-bit number, the 15-digit number may be repeated, but the odds are too small, too small to be ignored, and even if repeated, we lost the most users are only 0.5% Only.
String M_szdevidshort ="very"+ 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;// --bit
"35" plus the back of the 13 bits altogether 15 bits, we can get 355715565309247 such a bunch of numbers, do not need any permission, very convenient.
//Get a unique psuedo ID Public StaticStringgetuniquepsuedoid() {String serial =NULL; String M_szdevidshort ="very"+ Build.BOARD.length ()%Ten+ Build.BRAND.length ()%Ten+ Build.CPU_ABI.length ()%Ten+ Build.DEVICE.length ()%Ten+ Build.DISPLAY.length ()%Ten+ Build.HOST.length ()%Ten+ Build.ID.length ()%Ten+ Build.MANUFACTURER.length ()%Ten+ Build.MODEL.length ()%Ten+ Build.PRODUCT.length ()%Ten+ Build.TAGS.length ()%Ten+ Build.TYPE.length ()%Ten+ Build.USER.length ()%Ten;//13-bit Try{serial = Android.os.Build.class.getField ("SERIAL"). Get (NULL). ToString ();//api>=9 using the serial number return NewUUID (M_szdevidshort.hashcode (), Serial.hashcode ()). ToString (); }Catch(Exception Exception) {//serial requires an initializationserial ="Serial";//A random initialization}//15-digit numbers pieced together using hardware information return NewUUID (M_szdevidshort.hashcode (), Serial.hashcode ()). ToString ();
Will eventually get such a bunch of id:00000000-28ee-3eab-ffff-ffffe9374e72
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Does not require any permissions to get the unique ID of an Android device