Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 732
Vinil Chandran Avatar asked Mar 14 '23 10:03

Vinil Chandran


1 Answers

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

like image 53
CommonsWare Avatar answered May 08 '23 06:05

CommonsWare