question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Discussion] `getUniqueID` for Android should use another implementation

See original GitHub issue

getUniqueID function for android returns the constant ANDROID_ID. Based on an official post from Google at the android developers blog, the ANDROID_ID is not reliable.

ANDROID_ID seems a good choice for a unique device identifier. There are downsides: First, it is not 100% reliable on releases of Android prior to 2.2 (“Froyo”). Also, there has been at least one widely-observed bug in a popular handset from a major manufacturer, where every instance has the same ANDROID_ID.

In another document from google, they suggest to identify the app create a UUID and store it at the internal storage.

In cases where an Instance ID isn’t practical, custom globally unique IDs (GUIDs) can also be used to uniquely identify an app instance. The simplest way to do so is by generating your own GUID using the following code.

They also recommend to not use the ANDROID_ID.

#1: Avoid using hardware identifiers. Hardware identifiers such as SSAID (Android ID) and IMEI can be avoided in most use-cases without limiting required functionality.

My suggestion is change the getUniqueID function to return a previously generate UUID. If there is no one available, generate it, store it and return that value. Basically is to implement the google’s suggestion.

WDYT? I am offering to implement this.

\cc @machour

Refs: https://github.com/rebeccahughes/react-native-device-info/issues/60

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
schumanndcommented, Sep 5, 2018

When will this be merged? I can see the current behavior causing bugs for people, as it did for me. Not only does the android getUniqueID() not produce a hex number of length 32 like the iOS version does, it doesn’t even reliably produce a 16 length hex. Some models (maybe even all?) drop leading zeroes. Sure, it was my fault for assuming it didn’t do that, but I can see this happening to other people as well. Having to manually pad the output of getUniqueID also seems unnecessary.

So +1 to this PR!

3reactions
SandroMachadocommented, Mar 14, 2018

I think that we should keep this on native side, to take the advantage of the apple/iOS api, that is really well designed.

On Android, like I said before, I can make a PR to update this API to match the iOS behaviour (removing the vendor logic) since they have an API to generate UUID (UUID.randomUUID().toString();). WDYT?

Also, to generate a UUID on JS side, from my search, I didn’t find any solution that does not relays on the random string generation method, that is not the most desirable solution since it can lead to collisions and that should not happens.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Discussion] `getUniqueID` for Android should use another ...
ANDROID_ID seems a good choice for a unique device identifier. There are downsides: First, it is not 100% reliable on releases of Android...
Read more >
Is there a unique Android device ID? - Stack Overflow
Based on Google's recommendations, I implemented a class that will generate a unique UUID for each device, using ANDROID_ID as the seed where...
Read more >
Best practices for unique identifiers - Android Developers
This document provides guidance for selecting appropriate identifiers for your app based on your use case. For a general look at Android permissions, ......
Read more >
How to Get the Unique ID of an Android Device?
We can get IDs such as a device ID, IMEI which is also a unique ID, and many others. In this article, we...
Read more >
Get unique id for user | B4X Programming Forum
According to Android rules, We cannot use android_id or device_id or mac_address in new version android. As well, Use sms is not good...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found