I'm working on an android project in which the activation process is done against the device Id . So I have had to generate a unique id for each device. I got two ways by surfing the net.
In this case I generate the ID as below.
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String uid = tManager.getDeviceId();
But it gave a combination of "0" for emulator and a unique value for the actual device.
And the second way is as below
String android_id = Secure.getString(Main.this.getContentResolver(),Secure.ANDROID_ID);
This gave a unique value even for the emulator . So what is the different between these two IDs. which one is more preferable for my requirement.
Generating a device id is actually not as simple as it seems since the result may vary depending on the android version, manufacturer, etc.
Checkout this great post which explains the pros and cons of each method of generating a device id: http://developer.samsung.com/android/technical-docs/How-to-retrieve-the-Device-Unique-ID-from-android-device
This one will give you the unique device ID, you can go for it
import android.provider.Settings.Secure;
String android_id = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID);
*Note that this will change on Factory Reset, Do it on your own risk! or can be altered on rooted phone!
and this article will give you all the unique information which you can retrieve from the deivce such as..
String android_id = Secure.getString(Main.this.getContentResolver(),Secure.ANDROID_ID);
gives 64-bit number (as a hex string) that is randomly generated on the device's first boot and should remain constant for the lifetime of the device (The value may change if a factory reset is performed on the device.) ANDROID_ID seems a good choice for a unique device identifier.
while
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String uid = tManager.getDeviceId();
gives the IMEI, MEID, ESN and IMSI of the phone, which is unique to that piece of hardware which is a constant through out the lifetime of the device.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.