Get the IMEI of the phone - Android android.telephony

Android examples for android.telephony:TelephonyManager

Description

Get the IMEI of the phone

Demo Code

import android.content.Context;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

public class Main {

  private static Context ctx;

  public static String getDeviceIMEI() {
    String strIMEI = null;/*from w  w w.  j  a va  2  s . com*/

    try {
      TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
      strIMEI = tm.getDeviceId();
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (TextUtils.isEmpty(strIMEI)) {
      strIMEI = Long.toString(System.nanoTime());
    }

    return strIMEI;
  }

}

Related Tutorials