Rasoul Miri
Rasoul Miri

Reputation: 12222

why shouldShowRequestPermissionRationale not work?

how can use shouldShowRequestPermissionRationale before call permission and use in Activity.

because before ActivityCompat.requestPermissions this return false

if(ActivityCompat.shouldShowRequestPermissionRationale(context,permission)){
    // true
}else{
    // false (always false)
}

Upvotes: 0

Views: 1612

Answers (2)

cracktichi
cracktichi

Reputation: 13

Addition info: Some case must use correct mapping permission requested and permission use to check shouldShowRequestPermissionRationale.

In my case, I had used permission "granular media permissions" of Android 13 (READ_MEDIA_IMAGES/READ_MEDIA_AUDIO/READ_MEDIA_VIDEO) on device Android 10 and function shouldShowRequestPermissionRationale alway return false.

When i try use READ_EXTERNAL_STORAGE, it' working and return true when use not have choose "Never ask again"

So let try old basicly permission before try another permission.

Good luck!

Upvotes: 0

Nabin Bhandari
Nabin Bhandari

Reputation: 16379

The method shouldShowRequestPermissionRationale returns true if it is required to explain the user why the permission is required. In the first time the permission is requested, this method returns false.

But if the user denies the permission once, when the permission is requested another time, this method returns true because it might be a good idea to explain the user why this permission is required for the app.

When the permission is already granted, this method will return false.

So a good practice would be to first check what this method returns and if it is required to explain to the user, explain it using a dialog or something followed by requesting the permission, otherwise ask the permission directly.

You can also have a look at my library which ease up this whole process and other processes regarding run-time permissions.

Upvotes: 3

Related Questions