2

I came to know the privacy changes for Android 10 and I'm quite clear that third-party apps won't be able to get IMEI now. But one thing from documentation is creating confusion for me.

They state

If your app targets Android 9 (API level 28) or lower, the method returns null or placeholder data if the app has the READ_PHONE_STATE permission. Otherwise, a SecurityException occurs.

which means that on Android devices with API LEVEL 28 or lower, this method returns null or placeholder data, even if the app is having READ_PHONE_STATE permission. Right?

But I have tested this thing on my app targetting API LEVEL 28 and I am still able to get IMEI number with the following.

if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
            fragment.requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_CODE);
 }
 TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
 String deviceId = telephonyManager.getImei();

Shouldn't it send me NULL or placeholder (garbage) data?

any idea about it? or am I misinterpreting it?

Bilal
  • 1,034
  • 11
  • 23

1 Answers1

1

You're misinterpreting it. What documentation says, is:

If your application targets Android 9 (API level 28) or lower, then it will return null or placeholder data when running on Android 10 device.

Documentation describes here how it will behave on Android 10 in case you don't target Android 10. It's so applications don't suddenly break in strange ways despite not being updated. It has no effect on Android 9 devices (and on emulators that emulate Android 9 devices, which is probably what you're testing it with when targeting API level 28).

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
stasiaks
  • 1,268
  • 2
  • 14
  • 31