Where and when is generated android.Build.SERIAL in AOSP?

一笑奈何 提交于 2019-12-02 16:16:29

问题


I know, that android.Build.SERIAL is generated at first device boot, but I can't locate where and when exactly. I'm building AOSP Jelly Bean, Android tablet, nosdcard.

2nd question: is this serial number really unique for all Android devices?


回答1:


According to this thread, it clearly says that it's unique, but added since API 9 and may be not present on all devices.

If you're writing your app for a specific device's model, you could direclty check if it has an IMEI. Otherwise, as you said, I recommend you to write a custom ID generator module.
You will be sure that your ID will be unique and available for all devices.

IMEI represents the serial number of the device. It's sure it's unique. Two different devices can't have the same serial number.

To get the serial number of the device you just have to call :

String serial =  Build.SERIAL;

It exists another approach. You can get the id by calling Secure.ANDROID_ID.

A 64-bit number (as a hex string) that is randomly generated on the device's first boot and should remain constant for the lifetime of the device. (The value may change if a factory reset is performed on the device.)

private final String ANDROID_ID = Secure.getString(getContext().getContentResolver(),
                                                        Secure.ANDROID_ID);

Take care because it says that the value MAY change if a factory reset is performed.



来源:https://stackoverflow.com/questions/16645782/where-and-when-is-generated-android-build-serial-in-aosp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!