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.
I have tried putting public rp in MainPage and Starter (because everybody else seems to). Same result.
Log:
Other pertinent Stuff
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 = false | This 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_Resume | Enabling 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: