'Unique Identifier for Android Device - Unavailable
I want to use a Unique identifier for my library as multiple app in the same phone can utilise same unique ID. For example Android Phone A - can have 3 apps in the Phone A with same library integrated with all 3 apps, so all 3 must use the same ID to identify this as 1 device, rather than having 3 different IDs. Additionally, this app can be released from 3 different build machines and the app package names might not be known always.
- I have tried using Advertisment ID but it not achievable in all phones, few phones give access where few fail to retrive it.
- IMEI - requires additional permission and not achievable after android 10 as mostly the results achieved are empty string
- I have tried Android ID which is unique but if you have 2 different build machine for different or same apk it will assign 2 different Android ID rather than 1.
- Tried Shared preferance, Broadcast reciver, Content Provider and File R&W approach to create own unique Identifier but all of them fail to achieve.
- As for Broadcast Reciever both app need to be active at the same time to share information
- For Content Provider can only have 1 Content provider with same name and if the particular app created the content provider is deleted than the content provider is also deleted.
- Shared preference need to provide the package name for other application and read mode is not available. It do not work with the library package name, it requires app package name.
- File R&W - Some phone works and some dont, sometimes after deleting the file, it still shows file exist, some manufacture phone do not allow read from public directories.
Devices tested: Samsung - Android 9, 10 and 11 MI - Android 9, 10 and 11 Huawei- Android 9 and 10
Solution 1:[1]
As defined by Android Best Practices you should not use any Hardware ID like IMEI, MAC Address etc.
That leaves you with either Google Ad ID(GUID) or Firebase Installation Id(FID) or you can create your own unique ID solution which are all software generated ID's which can be reset by the user by things like factory reset.
If you are fine with the fact that some small sample size of users will still be able to reset the device ID which is expected among current companies then you can use the Account Manager API to share the ID generated by application. Although this is used to create a single login for all applications of a company by sharing the tokens and user name you can repurpose the Account Manager API for sharing the unique ID. Whenever an application is installed write your unique ID to Account Manager and when a new application is installed check if this ID already exists if it does then use the same else create a new one and write to Account Manager.
Still there will be some use-cases where the same phone will be represented by a new ID but such exceptional cases will be fractional and IMHO can be overlooked.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Taranmeet Singh |
