Android Question Wait For B4XPage_PermissionResult

mmieher

Active Member
Licensed User
Longtime User
Have been struggling with this for years. It seems to work, then not. Always works in a "small project", but keeps somehow mutating in the projects I care about.

Have watched this so many times: https://www.b4x.com/android/forum/threads/runtime-permissions-android-6-0-permissions.67689/#content
I have also repeatedly watched the micro-video of one of the Erel(s) typing out the Permission_Result line. How do you pause that?
https://www.b4x.com/android/forum/t...ow-to-handle-permissionresult.118902/#content

ALL THIS WORKS FINE ON A FRESH INSTALL OF THE APP. It does not work on all subsequent instances.

In the following example, Wait For B4XPage_PermissionResult is definitely not waiting. From the log, I see all kinds of resuming and pausing, but the app blows right past the WAIT even though the permission has not been granted.
B4X:
Private Sub CheckPermissions As ResumableSub
    Dim fLocation As Boolean = Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
    Log(fLocation)
    If fLocation = False Then
        PermissionsPage.Initialize("PermissionsPage")
        Root.AddView(PermissionsPage,0,0,100%x,100%y)
        PermissionsPage.LoadLayout("Permissions")
        UTIL.SetAllTags(PermissionsPage)
      
        Dim Args() As Object = Array("CheckPermissions", -1 , -3)
        Wait For (WaitKbd(Args, Null)) complete (rValue As WaitKbdType)
        If rValue.Tag <> -3 Then
            ExitApplication
        End If
      
        Log("Check PERMISSION_ACCESS_FINE_LOCATION")
        Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
        Wait For B4XPage_PermissionResult(Permission As String, Result As Boolean)
        Log("After Permission Wait")
      
        If Not(Result) Then
            Dim answ As Object
            answ = xui.MsgboxAsync("App cannot be used without permission.  Please restart and grant access.","Permissions Defect")
            Wait For (answ) Msgbox_Result (exitResult As Int)
            ExitApplication
        End If
 
    Else    '    permission already granted
        Starter.StartGPS
    End If
  
    Return True

End Sub

I have tried putting public rp in MainPage and Starter (because everybody else seems to). Same result.

Log:

rValue.Tag = -3
Check PERMISSION_ACCESS_FINE_LOCATION
** Activity (main) Pause event (activity is not paused). **
*** mainpage: B4XPage_Disappear [mainpage]
*** mainpage: B4XPage_Background [mainpage]
*** newuser: B4XPage_Background [mainpage]
MAIN PAGE: Permission Result = falseThis is fired in Main module in Activity_PermissionResult. Result is CORRECT.
*** mainpage: B4XPage_PermissionResult [mainpage]Hooray, the Delegate worked.
** Activity (main) Resume ** You lied above when you said ACTIVITY IS NOT PAUSED
B4xMain 07:39:42 Page_ResumeEnabling the above lie.
After Permission Wait But... But... I never got to converse with a Permissions Dialog?
** Activity (main) Pause event (activity is not paused). **Really? Again?

Other pertinent Stuff
B4X:
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    LogColor("MAIN PAGE:  Permission Result = " & Result, Colors.Red)
    B4XPages.Delegate.Activity_PermissionResult(Permission, Result)
End Sub

B4X:
AddPermission("android.permission.ACCESS_FINE_LOCATION")
 
Last edited:

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
In your comments, you say that the first time the dialog appears, how do you respond to the dialog?

I think this is a pertinent line from Erel's tutorial: (https://www.b4x.com/android/forum/threads/runtime-permissions-android-6-0-permissions.67689/#content)
- Testing the permissions can be confusing as the user only needs to give permissions once. The solution is to uninstall the app from the device. Click on Ctrl + P (clean project) in the IDE and run again.

If the permission has been refused, the permission dialog is NOT normally shown again.
 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
In your comments, you say that the first time the dialog appears, how do you respond to the dialog?

I think this is a pertinent line from Erel's tutorial: (https://www.b4x.com/android/forum/threads/runtime-permissions-android-6-0-permissions.67689/#content)


If the permission has been refused, the permission dialog is NOT normally shown again.
I was starting off with DENY to code through all the possibilities. Got stuck on the second run when rp.Checkie correctly returned that permission is false, but rp.CheckAndRequest does not show a dialog box, and is returning a FALSE immediately.

I did not know that you had only one shot at accepting or denying a permission request. Its like that act-or-stumble-moment when you know you may never see that woman on the subway again. Could this be true? It must be the answer. Thank you.
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
As far as I am aware, yes.

I t makes sense as the user should not have to be bothered by the message after they have explicitly refused.
 
Upvote 0
Top