READ_PHONE_STATE permission seems to be actively rejected in Android 11

Viewed 4144

I have an application with following permissions in Manifest:

<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

I manually enabled all permissions through Settings in an Android 11 mobile. However, if I use ActivityCompat.checkSelfPermission(this,(Manifest.permission.READ_PHONE_STATE)) to check if READ_PHONE_STATE permission has been granted, the result is always PERMISSION_DENIED.

I then used ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_PHONE_STATE), 102), which simply calls onRequestPermissionsResult with grant result PERMISSION_DENIED immediately.

I reproduced this on two Android 11 devices (one physical, one emulator), and I tried changing the package name, uninstalling and reinstalling the app etc.

1 Answers

I figured out what went wrong. One of the libraries I was including had this:

Library's Manifest
<uses-permission
    android:name="android.permission.READ_PHONE_STATE"
    android:maxSdkVersion="29" />

and even though I defined this permission in my app manifest, the maxSdkVersion got into my app.

The solution is to remove the maxSdkVersion property in your app:

App's Manifest
<uses-permission
    android:name="android.permission.READ_PHONE_STATE"
    tools:remove="android:maxSdkVersion" />
Related