Android Question How to know if a "Don't ask again" permission has been checked?

Marcob

Member
Licensed User
Hello,

I usually place a Msgbox() before RuntimePermissions.CheckAndRequest() so to let the user have more details about such permission.
If the user check the box "Don't ask again", RuntimePermissions.CheckAndRequest() will stop opening the permission dialog, in that case I would like to avoid showing my Msgbox() too.

Is there a way to check the "Don't ask again" status of the permission?
 

MarkusR

Well-Known Member
Licensed User
i believe there is also RuntimePermissions.Check() , maybe u get useful information there or open your messagebox for user.
in one project i used a extra activity form with some checkboxed just for permission check.
the user have information there and a visual feedback for desired permissions.
i used also the state for the app logic.
 
Last edited:

DonManfred

Expert
Licensed User
Is there a way to check the "Don't ask again" status of the permission?
No. You just can check the permission of you are granted or not.
In case the user used Dont ask again then it was his decision not to get asked again. He need to go into the setting from your app and manually grant the permission (systemsettings).
 

Erel

Administrator
Staff member
Licensed User
Complete example:
B4X:
Sub Process_Globals
   Private rp As RuntimePermissions
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
   
End Sub

Sub Activity_Click
   If ShouldShowRequestPermissionRationale(rp.PERMISSION_READ_EXTERNAL_STORAGE) Then
       MsgboxAsync("We need permission to access the external storage in order to upload your personal photos to the cloud.", "")
       Wait For Msgbox_Result (Result As Int)
   End If
   rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
   Wait For Activity_PermissionResult (Permission As String, Success As Boolean)
   If Success Then
       For Each f As String In File.ListFiles(File.DirRootExternal)
           Log(f)
       Next
   End If
End Sub

Sub ShouldShowRequestPermissionRationale (Permission As String) As Boolean
   Dim ctxt As JavaObject
   ctxt.InitializeContext
   Dim ActivityCompat As JavaObject
   ActivityCompat.InitializeStatic("android.support.v4.app.ActivityCompat")
   Return ActivityCompat.RunMethod("shouldShowRequestPermissionRationale", Array(ctxt, Permission))
End Sub
https://developer.android.com/refer...tyCompat#shouldshowrequestpermissionrationale

Note that ShouldShowRequestPermissionRationale returns False when the permission is requested for the first time. Based on my tests it only returns True from the second request and until the "don't ask again" checkbox is checked.
 

Marcob

Member
Licensed User
see the post before yours...

You can send the user to the systemsetting
Thank DonManfred for your suggestion. My ideal solution is to show a msg just before the permission request appears, so the user could make the proper decision. Then, if "don't ask again" is selected, the msg should not appear anymore (as is the case with the permission request).

In this respect, Erel's reply is optimal (thank you very much for showing how to implement ShouldShowRequestPermissionRationale).
Unfortunately, due to the particular behaviour of this function, when the permission is requested for the first time, the msg won't be displayed (just when it is needed the most). Hopefully, this should fix it:

B4X:
Sub Process_Globals
   Private rp As RuntimePermissions
   Private manager as PreferenceManager
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
 
End Sub

Sub Activity_Click
   If rp.Check(rp.PERMISSION_READ_EXTERNAL_STORAGE)=False Then
      If ShouldShowRequestPermissionRationale(rp.PERMISSION_READ_EXTERNAL_STORAGE) Or manager.GetBoolean("msg_storage")=False Then
         MsgboxAsync("We need permission to access the external storage in order to upload your personal photos to the cloud.", "")
         Wait For Msgbox_Result (Result As Int)
         manager.SetBoolean("msg_storage",True)
      End If
      rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
      Wait For Activity_PermissionResult (Permission As String, result As Boolean)
      If Success Then
         For Each f As String In File.ListFiles(File.DirRootExternal)
            Log(f)
         Next
      End If
   Else
      manager.SetBoolean("msg_storage",False)
   End If
End Sub

Sub ShouldShowRequestPermissionRationale (Permission As String) As Boolean
   Dim ctxt As JavaObject
   ctxt.InitializeContext
   Dim ActivityCompat As JavaObject
   ActivityCompat.InitializeStatic("android.support.v4.app.ActivityCompat")
   Return ActivityCompat.RunMethod("shouldShowRequestPermissionRationale", Array(ctxt, Permission))
End Sub
 
Top