Android Question B4XPage_PermissionResult Confusion

mmieher

Active Member
Licensed User
Longtime User
I must be missing something fundamental here. I have read through forum and watched tutorials.

In a B4XPage app, everything is fine when doing CheckandRequest permission the first time. B4XPage_PermissionResult is raised. However, after that, the event is not raised. Execution stops on the WaitFor. Other events (like Click) are still fired.

Relevant stuff:

Manifest
B4X:
AddPermission("android.permission.ACCESS_FINE_LOCATION")

Main
B4X:
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    B4XPages.Delegate.Activity_PermissionResult(Permission, Result)
End Sub

B4XMainPage
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    
    Private rp As RuntimePermissions
    
End Sub

Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    CheckPermissions
End Sub

Private Sub CheckPermissions
    
    Log("1")
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Log("2")
    Wait For B4XPage_PermissionResult(Permission As String, Result As Boolean)
    Log("3")
    If Not(Result) Then
        Log("location deny")
    Else
        Log("past Location")
    End If
    
End Sub

Private Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X")
End Sub

Log 1st Time:

** Activity (main) Create, isFirst = true **
*** mainpage: B4XPage_Created
1
2
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
** Activity (main) Pause event (activity is not paused). **
*** mainpage: B4XPage_Disappear [mainpage]
*** mainpage: B4XPage_PermissionResult [mainpage]
** Activity (main) Resume **
*** mainpage: B4XPage_Appear [mainpage]
3
past Location


Log After Permission Granted:

** Activity (main) Create, isFirst = true **
*** mainpage: B4XPage_Created
1
2
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
 

agraham

Expert
Licensed User
Longtime User
Your project works for me, though I have to comment out the Robocopy line in B4XMainPage and add #Bridgelogger: True to Main to get it to log in Release mode. Did you run that test project yourself?

First time it asks for permission. Next upload it goes through with permission already granted
Logger connected to: Xiaomi Redmi Note 9 Pro
--------- beginning of system
--------- beginning of main
*** mainpage: B4XPage_PermissionResult [mainpage]
** Activity (main) Resume **
*** mainpage: B4XPage_Appear [mainpage]
3
past Location
** Activity (main) Pause event (activity is not paused). **
*** mainpage: B4XPage_Disappear [mainpage]
Logger connected to: Xiaomi Redmi Note 9 Pro
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
*** mainpage: B4XPage_Created
1
2
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
*** mainpage: B4XPage_PermissionResult [mainpage]
3
past Location
 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
Your project works for me, though I have to comment out the Robocopy line in B4XMainPage and add #Bridgelogger: True to Main to get it to log in Release mode. Did you run that test project yourself?

First time it asks for permission. Next upload it goes through with permission already granted
Hmmm. Thanks for checking. I never see the Log("3") output.

I decided my program logic was f'd up so I took a different route. Figured out a different way to trap user until they accept permissions or exit.
 
Upvote 0
Top