How to request for permission: READ_PRIVILEGED_PHONE_STATE?

Viewed 12179

How can I request for permission "android.permission.READ_PRIVILEGED_PHONE_STATE"? I know that starting from Android 10, third-party apps installed from the Google Play Store cannot declare privileged permissions.

https://developer.android.com/about/versions/10/privacy/changes#data-ids

However my app will not be distributet with Google Play Store. I will share the apk file and users will install aplication manually.

I have declared permission in manifest:

<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />

I'm also trying to request it as any regular permission:

if(ActivityCompat.checkSelfPermission(this.getApplicationContext(), "android.permission.READ_PRIVILEGED_PHONE_STATE") != PackageManager.PERMISSION_GRANTED)        {
            ActivityCompat.requestPermissions(this, new String[]{"android.permission.READ_PRIVILEGED_PHONE_STATE"},123);
        }

But nothing is happening. I'm not being prompted to grant this permission. No alert dialog is being presented. How can I request for this permission?

1 Answers

You cant put this permission for android 10 version. You could change your targetSdkVersion to below 29

Android 10 changes the permissions for device identifiers so that all device identifiers are now protected by the READ_PRIVILEGED_PHONE_STATE permission.The READ_PRIVILEGED_PHONE_STATE permission is only granted to apps signed with the platform key and privileged system apps.

reference:

https://source.android.com/devices/tech/config/device-identifiers

Related