Android How to - Get Device ID








Question

We would like to know how to get Device ID.

Answer

/*from w  w w.jav  a2  s . c o  m*/
import android.content.Context;
import android.telephony.TelephonyManager;

public class Main {
  public static String getDeviceId(Context context){
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return telephonyManager.getDeviceId();
  }
}