Vinil Chandran
Vinil Chandran

Reputation: 1561

Android Marshmallow - how to know "Never ask again" is checked before

I want to request for the permission android.permission.ACCESS_COARSE_LOCATION for getting tower location.

But before requesting for that permission, i want to know whether it is blocked by the user by checking "Never ask again" check box.

Is there a proper way to know "Never ask again" for a permission?

=======================Requirement==========================

I want to prevent user from entering the screen without granting location access permission.

So I am using the permission request as a function named requestLocation() which is called in onResume().

Inside requestLocation()

-> Check for permission

-> If : permission already granted, register update location.

-> ELSE : not granted, show dialogue for grant permission with two button

-> One button execute the code "ActivityCompat.requestPermissions(..........);" and showing the in-built pop up for permission.

-> Another button helps to exit from the application.

When deny or grant is flagged in onRequestPermissionsResult(), then requestLocation() will executed again.

But in the case when "Never show again" is checked and deny is clicked, the infinite loop will continue as like the following

onRequestPermissionsResult()=>

PERMISSION_DENIED =>

requestLocation()=>

Permission not granted =>

ActivityCompat.requestPermissions(..........); =>

onRequestPermissionsResult() => PERMISSION_DENIED =>requestLocation()=>

Permission not granted =>

ActivityCompat.requestPermissions(..........);

=>...............

So if I can understand whether "Never show again" is clicked or not, I can exit from the loop by checking it inside requestLocation().

Upvotes: 4

Views: 2042

Answers (4)

Dhaval Jivani
Dhaval Jivani

Reputation: 9697

I have good experience with Dexter library, Dexter is simplified requesting permission at runtime.

Upvotes: -1

CommonsWare
CommonsWare

Reputation: 1007659

If:

  • You have requested the permission previously, and
  • You do not have the permission (checkSelfPermission() indicates that it is denied), and
  • shouldShowRequestPermissionRationale() returns false

then the user has checked "never ask again".

Upvotes: 7

BooleanCheese
BooleanCheese

Reputation: 635

You don't need to know if the user checked the box or not. The system will handle it as if the user denied you every single time.

Just request the permission. It shouldn't make a difference from your applications standpoint if the user checked the "never ask again" box or if they're just denying you every single time.

http://developer.android.com/training/permissions/requesting.html

Upvotes: 1

Marcin Orlowski
Marcin Orlowski

Reputation: 75645

But before requesting for that permission, i want to know whether it is blocked by the user by checking "Never ask again" check box.

I do not think you can, but frankly I do not see a reason what you would need to care. If you got your flow correct then it is irrelevant how user denied your request.

Upvotes: 0

Related Questions