On the perfect solution for Android to obtain the unique identification of devices

This paper introduces the perfect solution for Android to obtain the unique identification of devices, which is shared with you as follows:

Sometimes it is necessary to identify the user equipment, so we hope to get a stable, reliable and unique identification code. Although such a device identification code is provided in the Android system, the stability and uniqueness are not ideal due to the limitations of the Android system version and the bug in the manufacturer's customized system. Other hardware information identification also has different degrees of problems due to system version, mobile phone hardware and other restrictions.

Some string codes with "ability" or "certain ability" as equipment identification are collected below.

DEVICE_ ID

This is a serial number provided by the Android system for developers to identify mobile devices. It is also a highly universal method among various methods. It can be said that almost all devices can return this serial number with good uniqueness.

This device_ ID can be obtained through the following methods:

If we really need to use the identification of real equipment, we may need to use device_ ID。 In the past, our Android device was a mobile phone, this device_ The ID can be obtained through telephonymanager. Getdeviceid(). It returns IMEI, meid or ESN code according to different mobile devices, but it will encounter many problems in the process of use:

MAC ADDRESS

You can use the WiFi or Bluetooth MAC address of the mobile phone as the device ID, but it is not recommended for the following two reasons:

Get WiFi MAC address:

Get Bluetooth MAC address:

Sim Serial Number

For Android 2.3 devices with SIM cards, the SIM serial number can be obtained through the following methods:

Note: for CDMA devices, a null value is returned!

ANDROID_ ID

When the device is started for the first time, the system will randomly generate a 64 bit number and save it in the form of hexadecimal string, which is Android_ ID, which will be reset when the device is wipe. It can be obtained by the following methods:

ANDROID_ ID can be used as equipment identification, but note:

Serial Number

For Android system version 2.3 and above, you can get the serial number through the following method, and non mobile devices can also get it through this interface.

The above methods have some limitations or bugs more or less. If it is not really necessary to bind the hardware itself, it is also a good choice to use the UUID generated by yourself, because this method does not need to access the resources of the device and has nothing to do with the device type.

Installtion ID

The principle of this method is to generate an ID when the program runs for the first time after installation. This method is different from the unique identification of the device. Different applications will generate different IDS, and the reinstallation of the same program will also be different. Therefore, this is not the unique ID of the device, but it can ensure that the ID of each user is different. It can be said that it is the unique ID used to identify each application (i.e. installation ID), which can be used to track the installation quantity of applications, etc.

Google developer blog provides such a framework:

Device unique ID

As can be seen from the above, there is no reliable method to obtain the unique ID of all manufacturers' devices in the Android system. Each method has its own scope of use and limitations, which is also caused by too many popular Android system versions, devices from different manufacturers and no unified standard.

From the current development point of view, the coexistence of multiple versions of the Android system will continue for a long time, and the Android system will not be monopolized by a device manufacturer. In the long run, the Android basic system will tend to be stable, and the device identification will be standardized as the basic part of the system. At this time, this problem is expected to be completely solved.

At present, the more feasible solution is to adapt one by one. On the premise of ensuring the convenience of most devices, if you can't obtain it, use other alternative information as the identification, that is, encapsulate a device ID by yourself, and ensure that it is related to the device hardware information as much as possible and the uniqueness of the identification through internal algorithms.

summary

Based on the above, in order to obtain the unique identification of the device more commonly on the device, we can implement such a class to generate a unique UUID for each device, with Android_ Based on ID, when the acquisition fails, take telephonymanager. Getdeviceid () as the alternative method. If it fails again, use the generation strategy of UUID.

Again, the following method is to generate the device ID. in most cases, the installation ID can meet our needs, but if the device ID is really needed, it can be realized in the following ways:

How do I get the unique ID of an Android phone?

Code: here is the way to read the only imsi-id / imei-id in Android.

Java:

Note: android.os.systemproperties is labeled @ hide, so it does not exist in the SDK. If you need to use it, you need Android source code support.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>