Returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones. Return null if device ID is not available. - Android Hardware

Android examples for Hardware:Device ID

Description

Returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones. Return null if device ID is not available.

Demo Code


//package com.java2s;

import android.content.Context;

import android.telephony.TelephonyManager;

public class Main {
    /**//from  w  ww  .  j av a  2  s  .  co  m
     * Returns the unique device ID,<br> 
     * for example, the IMEI for GSM and the MEID or ESN for CDMA phones.<br>
     * Return null if device ID is not available. 
     * <p>
     * Requires Permission:{@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
     * @param context
     * @return
     */
    public static final String obtainDeviceId(Context context) {
        TelephonyManager tm = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        return tm.getDeviceId();
    }
}

Related Tutorials