4

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().

Floern
  • 33,559
  • 24
  • 104
  • 119
Vinil Chandran
  • 1,563
  • 1
  • 19
  • 33
  • http://stackoverflow.com/questions/30719047/android-m-check-runtime-permission-how-to-determine-if-the-user-checked-nev ,look at this – Jagadeesh Govindaraj Feb 03 '16 at 18:36
  • Note: If the user turned down the permission request in the past and chose the Don't ask again option in the permission request system dialog, this method returns false. The method also returns false if a device policy prohibits the app from having that permission. – Vinil Chandran Feb 03 '16 at 20:32

4 Answers4

7

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".

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

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

BooleanCheese
  • 615
  • 12
  • 34
0

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.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
-1

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

Dhaval Jivani
  • 9,467
  • 2
  • 48
  • 42