3

In android 10, couldn't get device id using permission "READ_PHONE_STATE". I got an error while trying to get deviceID "The user 10296 does not meet the requirements to access device identifiers". I referred the developer site, but couldn't get proper solution. Also "READ_PRIVILEGE_PHONE_STATE" permission also not accessible.

Please prefer any solution to get deviceID from Android 10 mobile's and help me to resolve this issue. Thanks in advance

Arun Kumar
  • 31
  • 1
  • 1
  • 2

4 Answers4

7

getDeviceId() has been deprecated since API level 26.

"READ_PRIVILEGE_PHONE_STATE" is only accessible by The best practices suggest that you should "Avoid using hardware identifiers." for unique identifiers. You can use an instance id from firebase e.g FirebaseInstanceId.getInstance().getId();.

Or you can generate a custom globally-unique ID (GUID) to uniquely identify the app instance e.g String uniqueID = UUID.randomUUID().toString();

or the least recommended way

String deviceId = android.provider.Settings.Secure.getString(
                context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
Jitesh Prajapati
  • 2,533
  • 4
  • 29
  • 51
Joe Malebe
  • 614
  • 5
  • 6
2

You can also use this one, it's getting token from Firebase:-

String deviceId = FirebaseInstanceId.getInstance().getToken();

and this way is also working:-

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

Amit Sharma
  • 261
  • 1
  • 4
  • 20
  • have you checked it on different apps on same device, providing same value? – Arnold Brown Feb 04 '20 at 03:43
  • But according to Firebase documentation Instance ID is stable except when: 1) App deletes Instance ID 2) App is restored on a new device 3) User uninstalls/reinstall the app 4) User clears app data – Siddhpura Amit Feb 26 '20 at 08:35
1

As per the latest release in Android 10, Restriction on non-resettable device identifiers. pps must have the READ_PRIVILEGED_PHONE_STATE privileged permission in order to access the device's non-resettable identifiers, which include both IMEI and serial number.

enter image description here

Check this for Privacy Changes in Android 10

To avoid such scenarios use UUID.randomUUID().toString() that represents an immutable universally unique identifier (UUID). A UUID represents a 128-bit value.

0

This is the definitive solution !

String myuniqueID;   
int myversion = Integer.valueOf(android.os.Build.VERSION.SDK);
    if (myversion < 23) {
        WifiManager manager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = manager.getConnectionInfo();
        myuniqueID= info.getMacAddress();
        if (myuniqueID== null) {
            TelephonyManager mngr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

            if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
            myuniqueID= mngr.getDeviceId();
        }
    }
    else if (myversion > 23 && myversion < 29) {
        TelephonyManager mngr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        myuniqueID= mngr.getDeviceId();
    }
    else
    {
        String androidId = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
        myuniqueID= androidId;
    }