Reputation: 46856
I am using this call:
Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
To get a UID for the device. I think I am getting the same ID from multiple devices though. Should this be possible?
The ID in question is: 9774d56d682e549c and apparently there is an issue with several devices returning this ID http://code.google.com/p/android/issues/list?cursor=10603&updated=10603&ts=1295993403
Upvotes: 105
Views: 165259
Reputation: 807
I have recently implemented SecureId on my App. I will share my findings.
Secure.getString(context.contentResolver, Secure.ANDROID_ID)
On Xiaomi POCO X3, The ID is same. Whether you install it from apk or App store.
But on a Samsung Device. The secureId is different. If you install the APP from APK and if you install it from the App Store. You get a different unique ID.
Now, If I want to share my app for testing. I upload it to Play Store and download the signed APK from Play Store then share it to testers.
APK_SECURE_ID is different and SIGNED_APK_SECURE_ID is different on a Samsung phone.
Upvotes: 0
Reputation: 2239
There are multiple solution exist but none of them perfect. let's go one by one.
1. Unique Telephony Number (IMEI, MEID, ESN, IMSI)
This solution needs to request for android.permission.READ_PHONE_STATE to your user which can be hard to justify following the type of application you have made.
Furthermore, this solution is limited to smartphones because tablets don’t have telephony services. One advantage is that the value survives to factory resets on devices.
2. MAC Address
3. Serial Number
4. Secure Android ID
On a device first boot, a randomly value is generated and stored. This value is available via Settings.Secure.ANDROID_ID . It’s a 64-bit number that should remain constant for the lifetime of a device. ANDROID_ID seems a good choice for a unique device identifier because it’s available for smartphones and tablets.
String androidId = Settings.Secure.getString(getContentResolver(),Settings.Secure.ANDROID_ID);
However, the value may change if a factory reset is performed on the device. There is also a known bug with a popular handset from a manufacturer where every instance have the same ANDROID_ID. Clearly, the solution is not 100% reliable.
5. Use UUID
As the requirement for most of applications is to identify a particular installation and not a physical device, a good solution to get unique id for an user if to use UUID class. The following solution has been presented by Reto Meier from Google in a Google I/O presentation :
private static String uniqueID = null;
private static final String PREF_UNIQUE_ID = "PREF_UNIQUE_ID";
public synchronized static String id(Context context) {
if (uniqueID == null) {
SharedPreferences sharedPrefs = context.getSharedPreferences(
PREF_UNIQUE_ID, Context.MODE_PRIVATE);
uniqueID = sharedPrefs.getString(PREF_UNIQUE_ID, null);
if (uniqueID == null) {
uniqueID = UUID.randomUUID().toString();
Editor editor = sharedPrefs.edit();
editor.putString(PREF_UNIQUE_ID, uniqueID);
editor.commit();
}
} return uniqueID;
}
Identify a particular device on Android is not an easy thing. There are many good reasons to avoid that. Best solution is probably to identify a particular installation by using UUID solution. credit : blog
Upvotes: 28
Reputation: 9
//Fields
String myID;
int myversion = 0;
myversion = Integer.valueOf(android.os.Build.VERSION.SDK);
if (myversion < 23) {
TelephonyManager mngr = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
myID= mngr.getDeviceId();
}
else
{
myID =
Settings.Secure.getString(getApplicationContext().getContentResolver(),
Settings.Secure.ANDROID_ID);
}
Yes, Secure.ANDROID_ID is unique for each device.
Upvotes: 0
Reputation: 1051
So if you want something unique to the device itself, TM.getDeviceId()
should be sufficient.
Here is the code which shows how to get Telephony manager ID. The android Device ID that you are using can change on factory settings and also some manufacturers have issue in giving unique id.
TelephonyManager tm =
(TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
String androidId = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID);
Log.d("ID", "Android ID: " + androidId);
Log.d("ID", "Device ID : " + tm.getDeviceId());
Be sure to take permissions for TelephonyManager
by using
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Upvotes: 16
Reputation: 5517
With Android O the behaviour of the ANDROID_ID will change. The ANDROID_ID will be different per app per user on the phone.
Taken from: https://android-developers.googleblog.com/2017/04/changes-to-device-identifiers-in.html
Android ID
In O, Android ID (Settings.Secure.ANDROID_ID or SSAID) has a different value for each app and each user on the device. Developers requiring a device-scoped identifier, should instead use a resettable identifier, such as Advertising ID, giving users more control. Advertising ID also provides a user-facing setting to limit ad tracking.
Additionally in Android O:
Upvotes: 54
Reputation: 761
Just list an alternaitve solution here, the Advertising ID:
https://support.google.com/googleplay/android-developer/answer/6048248?hl=en
Copied from the link above:
The advertising ID is a unique, user-resettable ID for advertising, provided by Google Play services. It gives users better controls and provides developers with a simple, standard system to continue to monetize their apps. It enables users to reset their identifier or opt out of personalized ads (formerly known as interest-based ads) within Google Play apps.
The limitations are:
https://support.google.com/googleplay/android-developer/answer/113469?hl=en&rd=1#privacy
Upvotes: 1
Reputation: 13856
Check into this thread,. However you should be careful as it's documented as "can change upon factory reset". Use at your own risk, and it can be easily changed on a rooted phone. Also it appears as if some manufacturers have had issues with their phones having duplicate numbers thread. Depending on what your trying to do, I probably wouldnt use this as a UID.
Upvotes: 62
Reputation: 48871
I've read a few things about this and unfortunately the ANDROID_ID should not be relied on for uniquely identifying an individual device.
It doesn't seem to be enforced in Android compliance requirements and so manufacturers seem to implement it the way they choose including some using it more as a 'model' ID etc.
Also, be aware that even if a manufacturer has written a generator to make it a UUID (for example), it's not guaranteed to survive a factory reset.
Upvotes: 6