How to find serial number of Android device?

后端 未结 17 2170
借酒劲吻你
借酒劲吻你 2020-11-22 14:07

I need to use a unique ID for an Android app and I thought the serial number for the device would be a good candidate. How do I retrieve the serial number of an Android devi

17条回答
  •  被撕碎了的回忆
    2020-11-22 14:36

    For a simple number that is unique to the device and constant for its lifetime (barring a factory reset or hacking), use Settings.Secure.ANDROID_ID.

    String id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
    

    To use the device serial number (the one shown in "System Settings / About / Status") if available and fall back to Android ID:

    String serialNumber = Build.SERIAL != Build.UNKNOWN ? Build.SERIAL : Secure.getString(getContentResolver(), Secure.ANDROID_ID);
    

提交回复
热议问题