How to get the device's IMEI/ESN programmatically in android?

后端 未结 20 2534
滥情空心
滥情空心 2020-11-22 05:19

To identify each devices uniquely I would like to use the IMEI (or ESN number for CDMA devices). How to access this programmatically?

20条回答
  •  滥情空心
    2020-11-22 06:02

    Or you can use the ANDROID_ID setting from Android.Provider.Settings.System (as described here strazerre.com).

    This has the advantage that it doesn't require special permissions but can change if another application has write access and changes it (which is apparently unusual but not impossible).

    Just for reference here is the code from the blog:

    import android.provider.Settings;
    import android.provider.Settings.System;   
    
    String androidID = System.getString(this.getContentResolver(),Secure.ANDROID_ID);
    

    Implementation note: if the ID is critical to the system architecture you need to be aware that in practice some of the very low end Android phones & tablets have been found reusing the same ANDROID_ID (9774d56d682e549c was the value showing up in our logs)

提交回复
热议问题