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

前端 未结 1 409
栀梦
栀梦 2021-01-27 20:55

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

相关标签:
1条回答
  • 2021-01-27 21:30

    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.

    0 讨论(0)
提交回复
热议问题