RecencyEffect RecencyEffect - 1 year ago 112
Android Question

Android permission automatically denied on requestPermission from MainActivity

In the main activity of an Android application I check for permissions (

), detect I do not have them, and call
Then in
I almost immediately get denied permission, without a dialog ever showing.

I already confirmed the same permission in another activity of the same app (through
again, which works), so I expected this decision to be stored (for the session, or whatever), and I have never selected to deny the permission. Either way, the permission dialog is not displayed and the permission is denied automatically.

So far I have tested this on emulators of Android 7 and 6 (API 24 and 23).

I have tried:

I'm pretty stumped...

Here is the permission request (see comment in the code):

private fun askForPermissionOrSendRequest(view: View, permission: String) {
if (checkSelfPermission(permission) == PackageManager.PERMISSION_DENIED) {
if (shouldShowRequestPermissionRationale(permission)) {
cachedView = view
val explanationDialog = AlertDialog.Builder(this).setMessage("We need permissions to read your storage in order to show your profile image.").setOnDismissListener {

} else {
cachedView = view
// this branch is always hit - the permission seems to be missing every time
} else {

I immediately get to the result handler without a dialog showing up to ask me for permissions. I may or may not have confirmed the same permission in another (child) activity of the same app (doesn't seem to make a difference).

override fun onRequestPermissionsResult(requestCode: Int,
permissions: Array<String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)

when (requestCode) {
BSMainActivity.permissionRequestSendProfilePic -> {
// This gets hit, MANAGE_DOCUMENTS was denied
if (permissions.contains(Manifest.permission.MANAGE_DOCUMENTS) && grantResults[permissions.indexOf(Manifest.permission.MANAGE_DOCUMENTS)] == PackageManager.PERMISSION_DENIED) {
Log.w(logName, "Permission to open image was denied while sending a tag request: %s %s".format(
permissions.joinToString(",", "[", "]"),
grantResults.joinToString(",", "[", "]")

// send request regardless of the result for now

In my manifest I have the following:

<manifest xmlns:android=""

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>

Answer Source

Only dangerous permissions can be requested at runtime and MANAGE_DOCUMENTS is not a dangerous permission.

As per the MANAGE_DOCUMENTS documentation:

This permission should only be requested by the platform document management app. This permission cannot be granted to third-party apps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download