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

后端 未结 20 2504
滥情空心
滥情空心 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 05:49

    You can use this TelephonyManager TELEPHONY_SERVICE function to get unique device ID, Requires Permission: READ_PHONE_STATE

    
    

    Example, the IMEI for GSM and the MEID or ESN for CDMA phones.

    /**
     * Gets the device unique id called IMEI. Sometimes, this returns 00000000000000000 for the
     * rooted devices.
     **/
    public static String getDeviceImei(Context ctx) {
        TelephonyManager telephonyManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
        return telephonyManager.getDeviceId();
    }
    

    Return null if device ID is not available.

提交回复
热议问题