how to get an android device ID

This question already has an answer here:

  • Is there a unique Android device ID? 40 answers

  • Look at the constant ANDROID_ID in android.provider.Secure.Settings.

    http://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID

    There are three types of identifier on android phone.

  • IMEI

  • IMSI

    String ts = Context.TELEPHONY_SERVICE; TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(ts); String imsi = mTelephonyMgr.getSubscriberId(); String imei = mTelephonyMgr.getDeviceId();

  • Android ID It is a 64-bit hex string which is generated on the device's first boot. Generally it won't be changed unless is factory reset.

    Secure.getString(getContentResolver(), Secure.ANDROID_ID);


  • 使用下面的行,

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

    试试这个代码:

     Will return the MDN or MEID of the device depending on which radio the
     phone uses (GSM or CDMA). Each device MUST return a unique value here
     (assuming it's a phone). This should work for any Android device with a
      sim slot or CDMA radio. Requires READ_PHONE_STATE permission
    
    public static String getDeviceUID(Context context) {
        TelephonyManager tManager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        return tManager.getDeviceId();
    }
    
    
      The Android ID (a unique 64-bit value) as a hex string. Identical to that
      obtained by calling GoogleLoginService.getAndroidId(); it is also placed
      here so you can get it without binding to a service.
    
    public static String getAndroidID(Context context) {
        return Settings.System.getString(context.getContentResolver(),
                Settings.Secure.ANDROID_ID);
    }
    
    链接地址: http://www.djcxy.com/p/24652.html

    上一篇: 有没有什么办法从android获取唯一的设备ID

    下一篇: 如何获得Android设备ID