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

Discussion in 'Android Questions' started by Marcob, Dec 4, 2018.

  1. Marcob

    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?
     
  2. MarkusR

    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: Dec 4, 2018
  3. DonManfred

    DonManfred Expert Licensed User

    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).
     
  4. DonManfred

    DonManfred Expert Licensed User

    you can send the user to the systemsettings and describe what the user need to do to grant permission manually.
    Code:
    Dim in As Intent
       
    in.Initialize("android.settings.APPLICATION_DETAILS_SETTINGS","package:"&Application.PackageName)
       
    StartActivity(in)
     
  5. Marcob

    Marcob Member Licensed User

  6. DonManfred

    DonManfred Expert Licensed User

    see the post before yours...

    You can send the user to the systemsetting
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Complete example:
    Code:
    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 StringAs 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.
     
  8. Marcob

    Marcob Member Licensed User

    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:

    Code:
    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 StringAs 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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice