Should I use ANDROID_ID as device identification considering no factory reset?

1.4k Views Asked by At

I am developing an Android app where a single user can use the app only in one device by using the same Gmail account(for sign-in) . If the user wants to sign in the app on a different device, he won't be able to do it using the same Gmail account. I am using ANDROID_ID in my application to identify a unique device using the following command--

Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);

Is it the correct option in this case, since I have seen in the developer website that

    Avoid using hardware identifiers. In most use cases, you can avoid using hardware identifiers, such as 
SSAID (Android ID), without limiting required functionality.

             Android 10 (API level 29) adds restrictions for non-resettable dentifiers, which include both 
            IMEI and serial number. Your app must be a device or profile owner app, have
         special carrier permissions, or have the READ_PRIVILEGED_PHONE_STATE privileged permission
     in order to access these identifiers.

Link for the doc-

https://developer.android.com/training/articles/user-data-ids

Or is there any other way for doing the above? Thanks in advance.

2

There are 2 best solutions below

0
On

you can define your own rule to generate a unqiue id,then save it on sp. every time you should check,get it and compare with the data that service provide.

or you can also use advicement ID to as unqiue device id.

0
On

If possible use FirebaseInstanceId in your use case. Firebase Instance ID provides a unique identifier for each app instance and a mechanism to authenticate and authorize actions.

  1. Instance ID is stable except when:

  2. App deletes Instance ID

  3. App is restored on a new device

  4. User uninstalls/reinstall the app

  5. User clears app data

In case if you don't want to use FirebaseInstanceId, you can look for custom globally-unique IDs (GUIDs) to uniquely identify an app instance.

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

You can use this GUID for identifying if only one device is attached to a gmail id or not.