18

Possible Duplicate:
Is there a unique Android device ID?

I used below code to get android device IMEI and How can I change below code to get android device Unique ID.

String getDeviceID1(TelephonyManager phonyManager){
    String id = phonyManager.getDeviceId();
    if (id == null){
        id = "not available";
    }
    int phoneType = phonyManager.getPhoneType();
    switch(phoneType){
        case TelephonyManager.PHONE_TYPE_NONE:
            return "" + id;

        case TelephonyManager.PHONE_TYPE_GSM:
            return "" + id;

        case TelephonyManager.PHONE_TYPE_CDMA:
            return "" + id;

        /*
        *  for API Level 11 or above
        *  case TelephonyManager.PHONE_TYPE_SIP:
        *   return "SIP";
        */

        default:
            return "" + id;
    }

    //I used to show IMEI 

    TextView textDeviceID = (TextView)findViewById(R.id.deviceid);
    //retrieve a reference to an instance of TelephonyManager
    TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    textDeviceID.setText(getDeviceID1(telephonyManager));
}
Community
  • 1
  • 1
ArnoHlaMoe
  • 287
  • 1
  • 4
  • 10
  • you want to change IMEI ???? why ? – Lucifer Aug 30 '12 at 05:11
  • @Eric, its not a Duplicate Quetsion, its **Not a Real Question**. – Lucifer Aug 30 '12 at 05:12
  • @Lucifer The way he words it, it sounds like he wants to change it to get a *different* unique device ID, which is covered in that post... So, I guess it depends how you interpret the question. Either way, a vote to close is a vote to close. – Cat Aug 30 '12 at 05:14
  • 1
    @Lucifier : He doesn't want to change IMEI. He means to say that he has successfully implemented the program to get the IMEI. He is asking for what to change in the program to get Unique device ID instead of IMEI. – androidFan Aug 30 '12 at 05:16
  • @Lucifer I mean, I don't wanna show anymore IMEI in my app. I have to show android unique device id. – ArnoHlaMoe Aug 30 '12 at 05:16
  • **IMEI** it self is unique id, then what else you need ? – Lucifer Aug 30 '12 at 05:18
  • @Lucifer IMEI is better than Android Unique device id? – ArnoHlaMoe Aug 30 '12 at 05:20
  • @ArnoHlaMoe, it depends on your requirement. – Lucifer Aug 30 '12 at 05:22
  • @Eric, not duplicate question. I read Is there a unique Android device ID?..Post but I don't know how to change in my script. I am beginner. Please help me. – ArnoHlaMoe Aug 30 '12 at 05:23
  • @Eric , I believe now you are right :) – Lucifer Aug 30 '12 at 05:26

1 Answers1

25

In Android, you can get three different Unique Ids.

  • IMEI ( which you have in your code already )

    TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String id =  (getDeviceID1(telephonyManager));
    
  • Device ID

    String android_id = Secure.getString(getContext().getContentResolver(),
                                                    Secure.ANDROID_ID); 
    
  • Bluetooth Address ( this will also be unique for each device )

    private BluetoothAdapter mBtAdapter;
    
    // Get the local Bluetooth adapter
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    String deviceMacAddress = mBtAdapter.getAddress();
    
Community
  • 1
  • 1
Lucifer
  • 29,392
  • 25
  • 90
  • 143