5

Android Q has restricted to access for both IMEI and serial no. It is available only for platform and apps with special carrier permission. Also the permission READ_PRIVILEGED_PHONE_STATE is not available for non platform apps.

Existing version(Android P, Android O, Android M) we have used the serial no for uniquely identified the device. Now we have faced the below Exception while tried to access the device identifier.

Android Q has restricted to access for both IMEI and serial no.

getSerial() in android.os.Build Class

06-21 12:37:07.460  1250  2555 W DevicePolicyManager: Package com.nagra.nmp.corepaktest (uid=10201, pid=32694) cannot access Device IDs
06-21 12:37:07.460  1250  2555 W TelephonyPermissions: reportAccessDeniedToReadIdentifiers:com.nagra.nmp.corepaktest:getSerial:isPreinstalled=false:isPrivApp=false
06-21 12:37:07.464 32694 32718 W System.err: java.lang.SecurityException: getSerial: The user 10201 does not meet the requirements to access device identifiers.
06-21 12:37:07.464 32694 32718 W System.err:    at android.os.Parcel.createException(Parcel.java:2069)
06-21 12:37:07.464 32694 32718 W System.err:    at android.os.Parcel.readException(Parcel.java:2037)
06-21 12:37:07.465 32694 32718 W System.err:    at android.os.Parcel.readException(Parcel.java:1986)
06-21 12:37:07.465 32694 32718 W System.err:    at android.os.IDeviceIdentifiersPolicyService$Stub$Proxy.getSerialForPackage(IDeviceIdentifiersPolicyService.java:159)
06-21 12:37:07.465 32694 32718 W System.err:    at android.os.Build.getSerial(Build.java:149)
06-21 12:37:07.465 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestBridge.start(Native Method)
06-21 12:37:07.466 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestWrapper.start(TestWrapper.java:111)
06-21 12:37:07.466 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestWrapper.access$200(TestWrapper.java:58)
06-21 12:37:07.466 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestWrapper$WrapperThread.run(TestWrapper.java:427)

getDeviceId() in android.telephony.TelephonyManager Class

06-21 12:37:07.472  1250  2555 W DevicePolicyManager: Package com.nagra.nmp.corepaktest (uid=10201, pid=32694) cannot access Device IDs
06-21 12:37:07.472  2744  2764 W TelephonyPermissions: reportAccessDeniedToReadIdentifiers:com.nagra.nmp.corepaktest:getDeviceId:isPreinstalled=false:isPrivApp=false
06-21 12:37:07.473 32694 32718 W System.err: java.lang.SecurityException: getDeviceId: The user 10201 does not meet the requirements to access device identifiers.
06-21 12:37:07.474 32694 32718 W System.err:    at android.os.Parcel.createException(Parcel.java:2069)
06-21 12:37:07.474 32694 32718 W System.err:    at android.os.Parcel.readException(Parcel.java:2037)
06-21 12:37:07.474 32694 32718 W System.err:    at android.os.Parcel.readException(Parcel.java:1986)
06-21 12:37:07.474 32694 32718 W System.err:    at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:10278)
06-21 12:37:07.474 32694 32718 W System.err:    at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:1565)
06-21 12:37:07.474 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestBridge.start(Native Method)
06-21 12:37:07.474 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestWrapper.start(TestWrapper.java:111)
06-21 12:37:07.474 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestWrapper.access$200(TestWrapper.java:58)
06-21 12:37:07.474 32694 32718 W System.err:    at com.nagra.CppUnitForAndroid.TestWrapper$WrapperThread.run(TestWrapper.java:427)

Which one(Property/API) used for Uniquely identify the device?

HB.
  • 4,116
  • 4
  • 29
  • 53
VMS
  • 137
  • 2
  • 8

2 Answers2

3

Since hardware ids are restricted, you can use an almost reliable software id like ANDROID_ID:

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

I used almost since it can be changed on a rooted phone, but reliable on non-rooted devices.

Sdghasemi
  • 5,370
  • 1
  • 34
  • 42
  • 2
    ANDROID_ID, differ per user profile, but i would like to understand "Which one(Property/API) used for Uniquely identify the device across different installation and different user?". Which means it should remain same in below scenarios? 1. Install APP -> Un-Install APP -> Install APP. 2. Install App -> Upgrade to Android Q(X-1 to X) 3. Install App -> Upgrade to Android Q(X-1 to X) -> Un-Install APP -> Install APP. 4. LogIn with two user profile the device unique ID must be same. – VMS Jun 25 '19 at 03:50
  • @amin check out [this](https://medium.com/@ssaurel/how-to-retrieve-an-unique-id-to-identify-android-devices-6f99fd5369eb) article, hope you'll find what you need. – Sdghasemi Oct 14 '19 at 07:07
  • @amin if you mean the article, the fifth solution is api version free and seems credible to me, however it'll not remain the same on every app install. – Sdghasemi Oct 14 '19 at 07:28
  • android id gets changes in some cases, then how can it will become unique? – Amin Pinjari Oct 14 '19 at 07:52
  • Yes it work on All Android versions upto Q. Is there issue on using this? Will it change on any cause? – Arnold Brown Dec 13 '19 at 10:11
  • @Sdghasemi hi any issue on using this? – Arnold Brown Dec 13 '19 at 10:14
  • @ArnoldBrown the SSAID is there but not a reliable source of identification if you're planning for it not to change **at all**, since there has been some changes on O which you can read about [here](https://stackoverflow.com/a/43393373/4399414). – Sdghasemi Dec 13 '19 at 11:02
  • @Sdghasemi so we can get DeviceId upto 28 and get Android_ID for greater than 28? – Arnold Brown Dec 13 '19 at 12:20
  • @ArnoldBrown seems a reasonable move to have a hard-changing id to attach to. – Sdghasemi Dec 13 '19 at 16:09
  • its not a solution as if i have two app than its android_id is Different – pincy Sep 09 '20 at 09:51
0

Only system apps will have access to hardware IDs. If your app needs to identify unique instances of your app running on different devices, you should use an API such as Firebase InstanceID service but there are similar options available from different providers as well.

It's worth noting that Google discouraged using Hardware ID features even in older Android versions.

Vahid Amiri
  • 10,769
  • 13
  • 68
  • 113
  • Hi Vahid Amiri, Firebase Instance ID, Instance ID is stable except when: App deletes Instance ID App is restored on a new device User uninstalls/reinstall the app User clears app data It clearly mentioned in AD page, but i would like to understand "Which one(Property/API) used for Uniquely identify the device across different installation?". Which means it should remain same in below scenarios? 1. Install APP -> Un-Install APP -> Install APP. 2. Install App -> Upgrade to Android Q(X-1 to X) 3. Install App -> Upgrade to Android Q(X-1 to X) -> Un-Install APP -> Install APP. – VMS Jun 24 '19 at 14:46
  • @VMS As far as I know, such a thing is not currently possible and probably never will be as there are serious privacy concerns. – Vahid Amiri Jun 24 '19 at 15:50
  • Thanks for your valuable time spent for my query – VMS Jun 25 '19 at 03:51