How to find serial number of Android device?

后端 未结 17 1962
借酒劲吻你
借酒劲吻你 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:33

    Unique device ID of Android OS Device as String.

    String deviceId;
        final TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            if (mTelephony.getDeviceId() != null){
                deviceId = mTelephony.getDeviceId(); 
             }
            else{
                deviceId = Secure.getString(getApplicationContext().getContentResolver(),   Secure.ANDROID_ID); 
             }
    

    but I strngly recommend this method suggested by Google::

    Identifying App Installations

    0 讨论(0)
  • 2020-11-22 14:34

    I know this question is old but it can be done in one line of code

    String deviceID = Build.SERIAL;

    0 讨论(0)
  • 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);
    
    0 讨论(0)
  • 2020-11-22 14:41

    The IMEI is good but only works on Android devices with phone. You should consider support for Tablets or other Android devices as well, that do not have a phone.

    You have some alternatives like: Build class members, BT MAC, WLAN MAC, or even better - a combination of all these.

    I have explained these details in an article on my blog, see: http://www.pocketmagic.net/?p=1662

    0 讨论(0)
  • 2020-11-22 14:41

    As @haserman says:

    TelephonyManager tManager = (TelephonyManager)myActivity.getSystemService(Context.TELEPHONY_SERVICE);
    String uid = tManager.getDeviceId();
    

    But it's necessary including the permission in the manifest file:

    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    
    0 讨论(0)
提交回复
热议问题