ANDROID - Get persistent device identifier (UUID)
Asked Answered
P

1

6

I need a device identifier that persists after the app is uninstalled and reinstalled. I know that UUID class provides an identifier with the method

String uniqueID = UUID.randomUUID().toString();

but Android guideline is unclear about its scope and persistence. In next paragraph it says:

The Android Operating system offers a number of IDs with different behavior characteristics and which ID you should use depends on how those following characteristics work with your use-case. But these characteristics also come with privacy implications so it's important to understand how these characteristics play together.

Scope

Identifier scope explains which systems can access the identifier. Android identifier scope generally comes in three flavors:

Single app. the ID is internal to the app and not accessible to other apps.

Group of apps - the ID is accessible to a pre-defined group of related apps.

Device - the ID is accessible to all apps installed on the device. The wider the scope granted to an identifier, the greater the risk of it being used for tracking purposes. Conversely, if an identifier can only be accessed by a single app instance, it can’t be used to track a device across transactions in different apps.

Resettability and persistence

Resettability and persistence define the lifespan of the identifier and explain how it can be reset. Common reset triggers are: in-app resets, resets via System Settings, resets on launch, and resets on installation. Android Identifiers can have varying lifespans, but the lifespan is usually related to how the ID is reset:

Session-only - a new ID is used every time the user restarts the app.

Install-reset - a new ID is used every time user uninstalls and reinstalls the app.

FDR-reset - a new ID is used every time the user factory-resets the device.

FDR-persistent - the ID survives factory reset.

Resettability gives users the ability to create a new ID that is disassociated from any existing profile information. This is important because the longer, and more reliably, an identifier persists (e.g. across factory resets etc.), the greater the risk that the user may be subjected to long-term tracking. If the identifier is reset upon app reinstall, this reduces the persistence and provides a means for the ID to be reset, even if there is no explicit user control to reset it from within the app or the System Settings.

But I don't know how to get these identifiers, choosing my scope and persistence. Thanks

Presentationism answered 16/6, 2016 at 16:37 Comment(4)
What did you ultimately decide on using?Colson
I used Instance ID provided by Google, also if it changes after you unistall the app, it seemed the best choice, also if I had to change something in my app.Presentationism
By instance ID you mean ANDROID_ID?Colson
No, I mean this: InstanceIDPresentationism
P
1

I am using this:

String DeviceId = Settings.Secure.getString(c.getContentResolver(), Settings.Secure.ANDROID_ID);

Look this thread: Is there a unique Android device ID?

Panchito answered 16/6, 2016 at 17:14 Comment(5)
ANDROID_ID doesn't persist across factory resets.Tallowy
What resettability and persistence does this solution provide?Colson
I think its persistent until a factory reset as said Abdullah or a rom change. For me it's enough. I don't know if a system update change it too.Panchito
Thank you so much for this solution. Google guys cannot even document this. I tried Firebase Instance ID, UUID. Nothing worked. Agree with David - do not care about factory reset.. It works for me after app is uninstalled and reinstalled. Also, we use it in an SDK and want it to persist on multiple apps as well as app uninstalls. It achieved both.Cephalopod
The question submitter cited official Android documentation which clearly discourages the use of Hardware IDs. This answer is not recommendedWhoops

© 2022 - 2024 — McMap. All rights reserved.